update frontend

This commit is contained in:
Parsa Nazer
2026-05-28 10:32:03 +03:30
parent 481452eea7
commit 35864e61dd
14 changed files with 473 additions and 35 deletions
@@ -26,7 +26,7 @@ const useGetAllOrders = () => {
const handleGetAllOrders = async () => {
const { data } = await axios.get<GetAllOrdersResponse>(API_ENDPOINTS.orders.get_all, {
params: {
sort: sort.value ?? "created_at",
sort: sort.value ?? "-created_at",
status: status.value,
offset: Number(page.value) * 10 - 10,
limit: 10,
@@ -0,0 +1,30 @@
// imports
import { useQuery } from "@tanstack/vue-query";
import type { ComputedRef } from "vue";
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
// types
export type GetOrderResponse = OrderDetail;
const useGetOrder = (id: ComputedRef<string>) => {
// state
const { $axios: axios } = useNuxtApp();
// methods
const handleGetOrder = async () => {
const { data } = await axios.get<GetOrderResponse>(`${API_ENDPOINTS.orders.get_one}/${id.value}`);
return data;
};
return useQuery({
queryKey: [QUERY_KEYS.order, id],
queryFn: () => handleGetOrder(),
enabled: computed(() => !!id.value),
});
};
export default useGetOrder;
@@ -26,7 +26,7 @@ const useGetAllTickets = () => {
const handleGetAllTickets = async () => {
const { data } = await axios.get<GetAllTicketsResponse>(API_ENDPOINTS.tickets.get_all, {
params: {
sort: sort.value ?? "created_at",
sort: sort.value ?? "-created_at",
filter: status.value,
offset: Number(page.value) * 7 - 7,
limit: 7,
+15 -2
View File
@@ -1,11 +1,24 @@
// composables/usePersianDate.ts
import { format, toDate } from "date-fns-jalali";
import { format } from "date-fns-jalali";
import { faIR } from "date-fns-jalali/locale";
import { Jalali } from "jalali-ts";
export default function usePersianDate() {
const formatToPersian = (isoDate: string): string => {
try {
const date = toDate(new Date(isoDate));
const yearStr = isoDate.slice(0, 4);
const year = Number(yearStr);
// jDateTimeField from django_jalali sends Jalali years (13XX/14XX).
// Normal DateTimeField sends Gregorian (19XX/20XX). Detect by year
// and use jalali-ts to convert when needed — date-fns-jalali's
// parseISO doesn't actually do calendar conversion.
const date =
!Number.isNaN(year) && year < 1700
? Jalali.parse(isoDate).date
: new Date(isoDate);
if (isNaN(date.getTime())) return "Invalid date";
const persianDate = format(date, "yyyy/MM/dd", { locale: faIR });
@@ -1,12 +1,44 @@
// composables/usePersianTimeAgo.ts
import { formatDistance, toDate } from "date-fns-jalali";
import { formatDistance } from "date-fns-jalali";
import { faIR } from "date-fns-jalali/locale";
import { Jalali } from "jalali-ts";
export function usePersianTimeAgo(date: Date) {
const toGregorianDate = (input: Date | string): Date | null => {
if (input instanceof Date) {
return isNaN(input.getTime()) ? null : input;
}
if (typeof input !== "string" || !input) return null;
const yearStr = input.slice(0, 4);
const year = Number(yearStr);
// jDateTimeField from django_jalali serializes with the Jalali year
// (typically 13XX or 14XX). Anything below ~1700 is treated as Jalali
// and converted to the equivalent Gregorian moment via jalali-ts.
// date-fns-jalali's parseISO can't be used here — it parses the year
// numerically without calendar conversion.
if (!Number.isNaN(year) && year < 1700) {
try {
return Jalali.parse(input).date;
} catch {
return null;
}
}
const native = new Date(input);
return isNaN(native.getTime()) ? null : native;
};
export function usePersianTimeAgo(date: Date | string) {
const timeAgo = ref("");
const updateTimeAgo = () => {
timeAgo.value = formatDistance(toDate(date), new Date(), {
const parsed = toGregorianDate(date);
if (!parsed) {
timeAgo.value = "";
return;
}
timeAgo.value = formatDistance(parsed, new Date(), {
addSuffix: true,
locale: faIR,
});