about us
This commit is contained in:
@@ -25,7 +25,7 @@ const ModalConfrim: FC<Props> = (props: Props) => {
|
|||||||
title_header={t('confrim.subject')}
|
title_header={t('confrim.subject')}
|
||||||
isHeader
|
isHeader
|
||||||
>
|
>
|
||||||
<div className='mt-6'>
|
<div className='mt-6 w-[450px]'>
|
||||||
<div className='text-sm text-center'>
|
<div className='text-sm text-center'>
|
||||||
{
|
{
|
||||||
props.label ?
|
props.label ?
|
||||||
|
|||||||
+4
-1
@@ -52,7 +52,10 @@ export const Pages = {
|
|||||||
create: "/learning/create",
|
create: "/learning/create",
|
||||||
category: "/learning/category",
|
category: "/learning/category",
|
||||||
},
|
},
|
||||||
setting: "/setting",
|
pages: {
|
||||||
|
aboutUs: "/pages/about-us",
|
||||||
|
aboutUsCreate: "/pages/about-us/create",
|
||||||
|
},
|
||||||
wallet: "/wallet",
|
wallet: "/wallet",
|
||||||
profile: "/profile",
|
profile: "/profile",
|
||||||
customers: {
|
customers: {
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
import { type FC, useState } from 'react'
|
||||||
|
import { useCreateAboutUs } from './hooks/useSettingData'
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import type { CreateAboutUs } from './types/Types';
|
||||||
|
import * as Yup from 'yup'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import Input from '../../components/Input'
|
||||||
|
import Textarea from '../../components/Textarea'
|
||||||
|
import Button from '../../components/Button'
|
||||||
|
import { TickCircle } from 'iconsax-react'
|
||||||
|
import { useUploadSingle } from '../uploader/hooks/useUploaderData'
|
||||||
|
import UploadBoxDraggble from '@/components/UploadBoxDraggble'
|
||||||
|
import { toast } from 'react-toastify'
|
||||||
|
import { extractErrorMessage } from '@/helpers/utils'
|
||||||
|
import { Pages } from '@/config/Pages'
|
||||||
|
|
||||||
|
const AboutUsCreate: FC = () => {
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const uploadSingle = useUploadSingle()
|
||||||
|
const createAboutUs = useCreateAboutUs();
|
||||||
|
|
||||||
|
const [imageFile, setImageFile] = useState<File[]>([])
|
||||||
|
|
||||||
|
const formik = useFormik<CreateAboutUs>({
|
||||||
|
initialValues: {
|
||||||
|
title: '',
|
||||||
|
description: '',
|
||||||
|
imageUrl: '',
|
||||||
|
},
|
||||||
|
validationSchema: Yup.object({
|
||||||
|
title: Yup.string().required('عنوان درباره ما الزامی است'),
|
||||||
|
description: Yup.string().required('توضیحات درباره ما الزامی است'),
|
||||||
|
}),
|
||||||
|
onSubmit: async (values) => {
|
||||||
|
let imageUrl = values.imageUrl
|
||||||
|
|
||||||
|
if (imageFile.length > 0) {
|
||||||
|
const imageResponse = await uploadSingle.mutateAsync(imageFile[0])
|
||||||
|
imageUrl = imageResponse.results?.url?.url || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitData = {
|
||||||
|
...values,
|
||||||
|
imageUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
createAboutUs.mutate(submitData, {
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success('اطلاعات درباره ما با موفقیت ایجاد شد')
|
||||||
|
navigate(Pages.pages.aboutUs)
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast.error(extractErrorMessage(error))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='mt-4'>
|
||||||
|
<div className='flex justify-between items-center'>
|
||||||
|
<div className='flex items-center gap-3'>
|
||||||
|
<h1>ساخت درباره ما جدید</h1>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
className='px-6'
|
||||||
|
onClick={() => formik.handleSubmit()}
|
||||||
|
isLoading={createAboutUs.isPending || uploadSingle.isPending}
|
||||||
|
disabled={!formik.isValid || createAboutUs.isPending || uploadSingle.isPending}
|
||||||
|
>
|
||||||
|
<div className='flex gap-2 items-center'>
|
||||||
|
<TickCircle size={16} color='#fff' />
|
||||||
|
<div>ثبت درباره ما</div>
|
||||||
|
</div>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex gap-6 xl:mt-8 mt-6'>
|
||||||
|
{/* اطلاعات اصلی */}
|
||||||
|
<div className='flex-1 text-sm bg-white py-8 xl:px-10 px-6 rounded-3xl'>
|
||||||
|
<h2 className='text-lg font-medium mb-6'>اطلاعات اصلی</h2>
|
||||||
|
|
||||||
|
<div className='space-y-6'>
|
||||||
|
<Input
|
||||||
|
label='عنوان درباره ما'
|
||||||
|
placeholder='مثال: درباره فروشگاه ما'
|
||||||
|
{...formik.getFieldProps('title')}
|
||||||
|
error_text={formik.touched.title && formik.errors.title ? formik.errors.title : ''}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Textarea
|
||||||
|
label='توضیحات درباره ما'
|
||||||
|
placeholder='توضیحات کامل درباره ما را وارد کنید...'
|
||||||
|
{...formik.getFieldProps('description')}
|
||||||
|
error_text={formik.touched.description && formik.errors.description ? formik.errors.description : ''}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* فایلها */}
|
||||||
|
<div className='w-80 space-y-6'>
|
||||||
|
<div className='text-sm bg-white py-8 px-6 rounded-3xl'>
|
||||||
|
<h2 className='text-lg font-medium mb-6'>فایلها</h2>
|
||||||
|
|
||||||
|
<div className='space-y-6'>
|
||||||
|
<div>
|
||||||
|
<UploadBoxDraggble
|
||||||
|
label='تصویر درباره ما'
|
||||||
|
isMultiple={false}
|
||||||
|
onChange={(files) => setImageFile(files)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AboutUsCreate
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
import { type FC } from 'react'
|
||||||
|
import { useDeleteAboutUs, useGetAboutUs } from './hooks/useSettingData'
|
||||||
|
import { type AboutUsItem } from './types/Types'
|
||||||
|
import PageLoading from '../../components/PageLoading'
|
||||||
|
import Error from '../../components/Error'
|
||||||
|
import Td from '../../components/Td'
|
||||||
|
import { Calendar, DocumentText, Add } from 'iconsax-react'
|
||||||
|
import Button from '../../components/Button'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { Pages } from '@/config/Pages'
|
||||||
|
import TrashWithConfrim from '@/components/TrashWithConfrim'
|
||||||
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
|
|
||||||
|
const AboutUsList: FC = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const deleteAboutUs = useDeleteAboutUs();
|
||||||
|
const { data, isLoading, error } = useGetAboutUs();
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center items-center min-h-[400px]">
|
||||||
|
<PageLoading />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center items-center min-h-[400px]">
|
||||||
|
<Error errorText="خطا در بارگذاری اطلاعات درباره ما" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const aboutUsItems = data?.results?.aboutUs || [];
|
||||||
|
|
||||||
|
const formatDate = (dateString: string) => {
|
||||||
|
if (!dateString) return '-';
|
||||||
|
return new Date(dateString).toLocaleDateString('fa-IR');
|
||||||
|
};
|
||||||
|
|
||||||
|
const truncateText = (text: string, maxLength: number = 50) => {
|
||||||
|
if (text.length <= maxLength) return text;
|
||||||
|
return text.substring(0, maxLength) + '...';
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className='flex justify-end mt-5'>
|
||||||
|
<Button
|
||||||
|
onClick={() => navigate(Pages.pages.aboutUsCreate)}
|
||||||
|
className='w-fit'
|
||||||
|
>
|
||||||
|
<div className='flex gap-2 items-center'>
|
||||||
|
<Add size={16} color='#fff' />
|
||||||
|
<span>افزودن درباره ما</span>
|
||||||
|
</div>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className='relative overflow-x-auto rounded-3xl mt-5 w-full'>
|
||||||
|
<table className='w-full text-sm'>
|
||||||
|
<thead className='thead'>
|
||||||
|
<tr>
|
||||||
|
<Td text={'تصویر'} />
|
||||||
|
<Td text={'عنوان'} />
|
||||||
|
<Td text={'توضیحات'} />
|
||||||
|
<Td text={'تاریخ ایجاد'} />
|
||||||
|
<Td text={'عملیات'} />
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{aboutUsItems.length === 0 ? (
|
||||||
|
<tr className='tr'>
|
||||||
|
<td colSpan={4} className="text-center py-8 text-gray-500">
|
||||||
|
هیچ اطلاعاتی یافت نشد
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : (
|
||||||
|
aboutUsItems.map((item: AboutUsItem) => (
|
||||||
|
<tr key={item._id} className='tr'>
|
||||||
|
<Td text="">
|
||||||
|
<div className="w-16 h-16 rounded-lg overflow-hidden">
|
||||||
|
<img
|
||||||
|
src={item.imageUrl || '/placeholder-image.png'}
|
||||||
|
alt={item.title}
|
||||||
|
className="w-full h-full object-cover"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Td>
|
||||||
|
<Td text="">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<DocumentText size={16} color="#8C90A3" />
|
||||||
|
<span className="font-medium">{item.title}</span>
|
||||||
|
</div>
|
||||||
|
</Td>
|
||||||
|
<Td text="">
|
||||||
|
<div className="max-w-xs">
|
||||||
|
<span className="text-gray-600 text-sm">
|
||||||
|
{truncateText(item.description)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</Td>
|
||||||
|
<Td text="">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Calendar size={16} color="#8C90A3" />
|
||||||
|
<span>{formatDate(item.createdAt)}</span>
|
||||||
|
</div>
|
||||||
|
</Td>
|
||||||
|
<Td text="">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<TrashWithConfrim
|
||||||
|
isLoading={deleteAboutUs.isPending}
|
||||||
|
onDelete={() => {
|
||||||
|
deleteAboutUs.mutate(item._id, {
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['aboutUs'] })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AboutUsList
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import * as api from "../service/SettingService";
|
||||||
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
export const useGetAboutUs = () => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["aboutUs"],
|
||||||
|
queryFn: api.getAboutUs,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useCreateAboutUs = () => {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: api.createAboutUs,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDeleteAboutUs = () => {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: api.deleteAboutUs,
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import axios from "../../../config/axios";
|
||||||
|
import type { AboutUsResponse, CreateAboutUs } from "../types/Types";
|
||||||
|
|
||||||
|
export const getAboutUs = async (): Promise<AboutUsResponse> => {
|
||||||
|
const { data } = await axios.get("/about-us");
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createAboutUs = async (params: CreateAboutUs) => {
|
||||||
|
const { data } = await axios.post("/admin/settings/about-us", params);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteAboutUs = async (id: string) => {
|
||||||
|
const { data } = await axios.delete(`/admin/settings/about-us/${id}`);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
export interface AboutUsItem {
|
||||||
|
_id: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
imageUrl: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AboutUsResults {
|
||||||
|
aboutUs: AboutUsItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AboutUsResponse {
|
||||||
|
status: number;
|
||||||
|
success: boolean;
|
||||||
|
results: AboutUsResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CreateAboutUs {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
imageUrl: string;
|
||||||
|
}
|
||||||
@@ -44,6 +44,8 @@ import Fines from '@/pages/payment/Fines'
|
|||||||
import TicketsList from '@/pages/tickets/List'
|
import TicketsList from '@/pages/tickets/List'
|
||||||
import ProductReport from '@/pages/report/ProductReport'
|
import ProductReport from '@/pages/report/ProductReport'
|
||||||
import CategoryReport from '@/pages/report/Category'
|
import CategoryReport from '@/pages/report/Category'
|
||||||
|
import AboutUsList from '@/pages/setting/AboutUsList'
|
||||||
|
import AboutUsCreate from '@/pages/setting/AboutUsCreate'
|
||||||
const MainRouter: FC = () => {
|
const MainRouter: FC = () => {
|
||||||
|
|
||||||
const { hasSubMenu } = useSharedStore()
|
const { hasSubMenu } = useSharedStore()
|
||||||
@@ -111,6 +113,9 @@ const MainRouter: FC = () => {
|
|||||||
|
|
||||||
<Route path={Pages.report.product} element={<ProductReport />} />
|
<Route path={Pages.report.product} element={<ProductReport />} />
|
||||||
<Route path={Pages.report.category} element={<CategoryReport />} />
|
<Route path={Pages.report.category} element={<CategoryReport />} />
|
||||||
|
|
||||||
|
<Route path={Pages.pages.aboutUs} element={<AboutUsList />} />
|
||||||
|
<Route path={Pages.pages.aboutUsCreate} element={<AboutUsCreate />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -800,8 +800,8 @@ const PagesSubMenu: FC = () => {
|
|||||||
<div className='flex flex-col mt-10 gap-4'>
|
<div className='flex flex-col mt-10 gap-4'>
|
||||||
<SubMenuItem
|
<SubMenuItem
|
||||||
title={'درباره ما'}
|
title={'درباره ما'}
|
||||||
isActive={isActive('about')}
|
isActive={isActive('about-us')}
|
||||||
link="/pages/about"
|
link={Pages.pages.aboutUs}
|
||||||
/>
|
/>
|
||||||
<SubMenuItem
|
<SubMenuItem
|
||||||
title={'سوالات متداول'}
|
title={'سوالات متداول'}
|
||||||
|
|||||||
Reference in New Issue
Block a user