base structure

This commit is contained in:
hamid zarghami
2025-11-12 11:45:13 +03:30
parent d9560b7d32
commit d36b8e40f0
26 changed files with 1083 additions and 8 deletions
+27
View File
@@ -0,0 +1,27 @@
export const formatDate = (dateString: string): string => {
const date = new Date(dateString);
return new Intl.DateTimeFormat("fa-IR", {
year: "numeric",
month: "long",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
}).format(date);
};
export const formatDateShort = (dateString: string): string => {
const date = new Date(dateString);
return new Intl.DateTimeFormat("fa-IR", {
year: "numeric",
month: "short",
day: "numeric",
}).format(date);
};
export const formatPrice = (price: number): string => {
return new Intl.NumberFormat("fa-IR", {
style: "decimal",
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}).format(price);
};
+29
View File
@@ -0,0 +1,29 @@
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
export type XOR<T, U> = T | U extends object
? (Without<T, U> & U) | (Without<U, T> & T)
: T | U;
export type ItemsSelectType = {
value: string;
label: string;
};
export type ErrorType = Error & {
response?: {
data?: {
error: {
message: string[];
};
};
};
};
export interface IGeneralError {
status: number;
success: boolean;
error: {
message: string;
details: string[];
};
}
+24
View File
@@ -0,0 +1,24 @@
import { twMerge } from "tailwind-merge";
import type { IGeneralError } from "./types";
/**
* Concatenates truthy classes into a space-separated string.
*
* @param classes - The classes to concatenate.
* @returns The concatenated classes.
*/
export const clx = (...classes: (string | boolean | undefined)[]): string => {
return twMerge(classes.filter(Boolean).join(" "));
};
export const extractErrorMessage = (
error: Error | unknown,
fallbackMessage: string = "خطایی رخ داده است"
): string => {
try {
const axiosError = error as { response?: { data: IGeneralError } };
return axiosError?.response?.data?.error?.details?.[0] || fallbackMessage;
} catch {
return fallbackMessage;
}
};