base package
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import axios from "axios";
|
||||
import { getToken } from "./func";
|
||||
// import { Pages } from "./Pages";
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: import.meta.env.VITE_BASE_URL,
|
||||
});
|
||||
|
||||
axiosInstance.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
},
|
||||
);
|
||||
|
||||
axiosInstance.interceptors.request.use(async function (config) {
|
||||
const tokenValue = await getToken();
|
||||
const token = tokenValue ? tokenValue : "";
|
||||
|
||||
config.headers.Authorization = "Bearer " + token;
|
||||
return config;
|
||||
});
|
||||
|
||||
export default axiosInstance;
|
||||
@@ -0,0 +1,68 @@
|
||||
export function isEmail(input: string): boolean {
|
||||
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
||||
return emailRegex.test(input);
|
||||
}
|
||||
|
||||
export function NumberFormat(number: number): string {
|
||||
return Intl.NumberFormat("fa-IR").format(number);
|
||||
// return Intl.NumberFormat("fa-IR").format(number);
|
||||
}
|
||||
|
||||
export const timeAgo = (date: string | Date): string => {
|
||||
const now = new Date();
|
||||
const past = new Date(date);
|
||||
const diff = Math.floor((now.getTime() - past.getTime()) / 1000); // اختلاف بر حسب ثانیه
|
||||
|
||||
const units = [
|
||||
{ name: "سال", value: 60 * 60 * 24 * 365 },
|
||||
{ name: "ماه", value: 60 * 60 * 24 * 30 },
|
||||
{ name: "روز", value: 60 * 60 * 24 },
|
||||
{ name: "ساعت", value: 60 * 60 },
|
||||
{ name: "دقیقه", value: 60 },
|
||||
{ name: "ثانیه", value: 1 },
|
||||
];
|
||||
|
||||
for (const unit of units) {
|
||||
const amount = Math.floor(diff / unit.value);
|
||||
if (amount >= 1) return `${amount} ${unit.name} پیش`;
|
||||
}
|
||||
|
||||
return "همین الان";
|
||||
};
|
||||
|
||||
export const getToken = () => {
|
||||
return localStorage.get(import.meta.env.VITE_TOKEN_NAME);
|
||||
};
|
||||
|
||||
export const getRefreshToken = () => {
|
||||
return localStorage.get(import.meta.env.VITE_REFRESH_TOKEN_NAME);
|
||||
};
|
||||
|
||||
const isProduction = import.meta.env.MODE === "production";
|
||||
const domain = isProduction ? ".danakcorp.com" : window.location.hostname;
|
||||
|
||||
export const setToken = (token: string) => {
|
||||
localStorage.set(import.meta.env.VITE_TOKEN_NAME, token, { domain });
|
||||
};
|
||||
|
||||
export const setRefreshToken = (refreshToken: string) => {
|
||||
localStorage.set(import.meta.env.VITE_REFRESH_TOKEN_NAME, refreshToken, {
|
||||
domain,
|
||||
});
|
||||
};
|
||||
|
||||
export const removeToken = () => {
|
||||
localStorage.remove(import.meta.env.VITE_TOKEN_NAME, { domain, path: "/" });
|
||||
};
|
||||
|
||||
export const removeRefreshToken = () => {
|
||||
localStorage.remove(import.meta.env.VITE_REFRESH_TOKEN_NAME, {
|
||||
domain,
|
||||
path: "/",
|
||||
});
|
||||
};
|
||||
|
||||
export const getRedirectUrl = () => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
return urlParams.get("redirect");
|
||||
};
|
||||
+44
-47
@@ -1,10 +1,14 @@
|
||||
import Divider from '@/components/Divider'
|
||||
import { ArrowLeft, DocumentText } from 'iconsax-react'
|
||||
import { type FC } from 'react'
|
||||
import { useState, type FC } from 'react'
|
||||
import PdfIcon from '@/assets/images/PDF.svg'
|
||||
import Button from '@/components/Button'
|
||||
import Input from '@/components/Input'
|
||||
|
||||
const Home: FC = () => {
|
||||
|
||||
const [active, setActive] = useState<string>('')
|
||||
|
||||
return (
|
||||
<div className='mt-4 w-full'>
|
||||
<h1 className='text-lg font-light'>
|
||||
@@ -13,56 +17,15 @@ const Home: FC = () => {
|
||||
|
||||
<div className='mt-20 bg-white rounded-4xl p-10'>
|
||||
<div className='text-center'>
|
||||
سایز مورد نظر را انتخاب کنبد و یک کاتالوگ زیبا با ویرایشگر داناک بسازید
|
||||
سایز و نام مورد نظر را انتخاب کنبد و یک کاتالوگ زیبا با ویرایشگر داناک بسازید
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className='mt-8 flex justify-center gap-8'>
|
||||
<div className='w-[160px] h-[166px] rounded-[20px] border border-border flex items-center justify-center'>
|
||||
<div>
|
||||
<div className='size-[94px] bg-[#EEF0F7] rounded flex justify-center items-center'>
|
||||
<DocumentText size={24} color='black' />
|
||||
</div>
|
||||
|
||||
<div className='mt-3 text-center text-sm'>
|
||||
جزوه
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='w-[160px] h-[166px] rounded-[20px] border border-border flex items-center justify-center'>
|
||||
<div>
|
||||
<div className='size-[94px] bg-[#EEF0F7] rounded flex justify-center items-center'>
|
||||
<DocumentText size={24} color='black' />
|
||||
</div>
|
||||
|
||||
<div className='mt-3 text-center text-sm'>
|
||||
بروشور
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='w-[160px] h-[166px] rounded-[20px] border border-border flex items-center justify-center'>
|
||||
<div>
|
||||
<div className='size-[94px] bg-[#EEF0F7] rounded flex justify-center items-center'>
|
||||
<DocumentText size={24} color='black' />
|
||||
</div>
|
||||
|
||||
<div className='mt-3 text-center text-sm'>
|
||||
روزنامه
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='w-[160px] h-[166px] rounded-[20px] border border-border flex items-center justify-center'>
|
||||
<div>
|
||||
<div className='size-[94px] bg-[#EEF0F7] rounded flex justify-center items-center'>
|
||||
<DocumentText size={24} color='black' />
|
||||
</div>
|
||||
|
||||
<div className='mt-3 text-center text-sm'>
|
||||
Letter
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='w-[160px] h-[166px] rounded-[20px] border border-border flex items-center justify-center'>
|
||||
<div onClick={() => setActive('a4')} className={`
|
||||
w-[160px] h-[166px] rounded-[20px] border border-border flex items-center justify-center
|
||||
${active === 'a4' && 'border-black!'}
|
||||
`}>
|
||||
<div>
|
||||
<div className='size-[94px] bg-[#EEF0F7] rounded flex justify-center items-center'>
|
||||
<DocumentText size={24} color='black' />
|
||||
@@ -73,6 +36,40 @@ const Home: FC = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div onClick={() => setActive('a3')} className={`
|
||||
w-[160px] h-[166px] rounded-[20px] border border-border flex items-center justify-center
|
||||
${active === 'a3' && 'border-black!'}
|
||||
`}>
|
||||
<div>
|
||||
<div className='size-[94px] bg-[#EEF0F7] rounded flex justify-center items-center'>
|
||||
<DocumentText size={24} color='black' />
|
||||
</div>
|
||||
|
||||
<div className='mt-3 text-center text-sm'>
|
||||
A3
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div onClick={() => setActive('a5')} className={`
|
||||
w-[160px] h-[166px] rounded-[20px] border border-border flex items-center justify-center
|
||||
${active === 'a5' && 'border-black!'}
|
||||
`}>
|
||||
<div>
|
||||
<div className='size-[94px] bg-[#EEF0F7] rounded flex justify-center items-center'>
|
||||
<DocumentText size={24} color='black' />
|
||||
</div>
|
||||
|
||||
<div className='mt-3 text-center text-sm'>
|
||||
A5
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='mt-5'>
|
||||
<Input
|
||||
label='نام کاتالوگ'
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='flex justify-center'>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as api from "../service/HomeService";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
|
||||
export const useHomeData = () => {
|
||||
return useMutation({
|
||||
mutationFn: api.createCatalog,
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import axios from "@/config/axios";
|
||||
import type { CreateCatalogParamsType } from "../types/Types";
|
||||
|
||||
export const createCatalog = async (params: CreateCatalogParamsType) => {
|
||||
const { data } = await axios.post("/catalogs", params);
|
||||
return data;
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
export type CreateCatalogParamsType = {
|
||||
name: string;
|
||||
size: string;
|
||||
};
|
||||
Reference in New Issue
Block a user