contract
This commit is contained in:
@@ -204,5 +204,6 @@ export const Pages = {
|
|||||||
learning: "/sellers/learning",
|
learning: "/sellers/learning",
|
||||||
learningCreate: "/sellers/learning/create",
|
learningCreate: "/sellers/learning/create",
|
||||||
learningUpdate: "/sellers/learning/update/",
|
learningUpdate: "/sellers/learning/update/",
|
||||||
|
contract: "/sellers/contract",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import { type FC } from 'react'
|
||||||
|
import { useFormik } from 'formik'
|
||||||
|
import * as Yup from 'yup'
|
||||||
|
import { useGetContentContract, useUpdateContract } from './hooks/useSellerData'
|
||||||
|
import PageLoading from '@/components/PageLoading'
|
||||||
|
import Error from '@/components/Error'
|
||||||
|
import Button from '@/components/Button'
|
||||||
|
import TextEditor from '@/components/TextEditor'
|
||||||
|
import { TickCircle } from 'iconsax-react'
|
||||||
|
import { toast } from 'react-toastify'
|
||||||
|
import { extractErrorMessage } from '@/helpers/utils'
|
||||||
|
|
||||||
|
const validationSchema = Yup.object().shape({
|
||||||
|
content: Yup.string().required('محتوای قرارداد الزامی است')
|
||||||
|
})
|
||||||
|
|
||||||
|
const ContractPage: FC = () => {
|
||||||
|
const { data: contentContract, isLoading, error } = useGetContentContract()
|
||||||
|
const updateContractMutation = useUpdateContract()
|
||||||
|
|
||||||
|
const contract = contentContract?.results?.contract
|
||||||
|
const isDataLoaded = !!contract
|
||||||
|
|
||||||
|
const formik = useFormik({
|
||||||
|
initialValues: {
|
||||||
|
id: contract?._id || '',
|
||||||
|
content: contract?.content || '<p>در حال بارگذاری...</p>'
|
||||||
|
},
|
||||||
|
validationSchema,
|
||||||
|
enableReinitialize: true,
|
||||||
|
onSubmit: async (values) => {
|
||||||
|
updateContractMutation.mutate({
|
||||||
|
id: values.id,
|
||||||
|
content: values.content
|
||||||
|
}, {
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success('قرارداد با موفقیت بروزرسانی شد')
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast.error(extractErrorMessage(error))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <PageLoading />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <Error errorText="خطا در بارگذاری قرارداد" />
|
||||||
|
}
|
||||||
|
|
||||||
|
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={updateContractMutation.isPending}
|
||||||
|
disabled={!isDataLoaded || !formik.isValid || updateContractMutation.isPending}
|
||||||
|
>
|
||||||
|
<div className='flex gap-2 items-center'>
|
||||||
|
<TickCircle size={16} color='#fff' />
|
||||||
|
<div>بروزرسانی قرارداد</div>
|
||||||
|
</div>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='xl:mt-8 mt-6'>
|
||||||
|
<div className='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'>
|
||||||
|
<TextEditor
|
||||||
|
key={isDataLoaded ? 'loaded' : 'loading'}
|
||||||
|
value={formik.values.content}
|
||||||
|
onChange={(value) => formik.setFieldValue('content', value)}
|
||||||
|
placeholder='محتوای قرارداد را وارد کنید...'
|
||||||
|
height='h-[400px]'
|
||||||
|
/>
|
||||||
|
{formik.touched.content && formik.errors.content && (
|
||||||
|
<div className='text-red-500 text-sm mt-1'>
|
||||||
|
{String(formik.errors.content)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ContractPage
|
||||||
@@ -133,3 +133,16 @@ export const useDeleteLearning = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useGetContentContract = () => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["content-contract"],
|
||||||
|
queryFn: api.getContentContract,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useUpdateContract = () => {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: api.updateContract,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import type {
|
|||||||
GetLearningCategoryResponse,
|
GetLearningCategoryResponse,
|
||||||
GetLearningResponse,
|
GetLearningResponse,
|
||||||
CreateLearningType,
|
CreateLearningType,
|
||||||
|
UpdateContractType,
|
||||||
} from "../types/Types";
|
} from "../types/Types";
|
||||||
|
|
||||||
export const getSellers = async (
|
export const getSellers = async (
|
||||||
@@ -144,3 +145,16 @@ export const deleteLearning = async (id: string) => {
|
|||||||
const { data } = await axios.delete(`/admin/learning/${id}`);
|
const { data } = await axios.delete(`/admin/learning/${id}`);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getContentContract = async () => {
|
||||||
|
const { data } = await axios.get(`/admin/settings/contract`);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateContract = async (params: UpdateContractType) => {
|
||||||
|
const { data } = await axios.patch(
|
||||||
|
`/admin/settings/contract/${params.id}/update`,
|
||||||
|
params
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|||||||
@@ -362,3 +362,21 @@ export interface CreateLearningType {
|
|||||||
cover: string;
|
cover: string;
|
||||||
category: string;
|
category: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ContractResponse {
|
||||||
|
status: number;
|
||||||
|
success: boolean;
|
||||||
|
results: {
|
||||||
|
contract: {
|
||||||
|
_id: string;
|
||||||
|
content: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateContractType {
|
||||||
|
id: string;
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ import CategoryLearning from '@/pages/seller/CategoryLearning'
|
|||||||
import Learning from '@/pages/seller/Learning'
|
import Learning from '@/pages/seller/Learning'
|
||||||
import CreateLearning from '@/pages/seller/CreateLearning'
|
import CreateLearning from '@/pages/seller/CreateLearning'
|
||||||
import UpdateLearning from '@/pages/seller/UpdateLearning'
|
import UpdateLearning from '@/pages/seller/UpdateLearning'
|
||||||
|
import ContractPage from '@/pages/seller/Contract'
|
||||||
const MainRouter: FC = () => {
|
const MainRouter: FC = () => {
|
||||||
|
|
||||||
const { hasSubMenu } = useSharedStore()
|
const { hasSubMenu } = useSharedStore()
|
||||||
@@ -175,6 +176,7 @@ const MainRouter: FC = () => {
|
|||||||
<Route path={Pages.sellers.learning} element={<Learning />} />
|
<Route path={Pages.sellers.learning} element={<Learning />} />
|
||||||
<Route path={Pages.sellers.learningCreate} element={<CreateLearning />} />
|
<Route path={Pages.sellers.learningCreate} element={<CreateLearning />} />
|
||||||
<Route path={`${Pages.sellers.learningUpdate}:id`} element={<UpdateLearning />} />
|
<Route path={`${Pages.sellers.learningUpdate}:id`} element={<UpdateLearning />} />
|
||||||
|
<Route path={Pages.sellers.contract} element={<ContractPage />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -523,8 +523,8 @@ const SellersSubMenu: FC = () => {
|
|||||||
/>
|
/>
|
||||||
<SubMenuItem
|
<SubMenuItem
|
||||||
title={'قرار داد'}
|
title={'قرار داد'}
|
||||||
isActive={isActive('contracts')}
|
isActive={isActive('contract')}
|
||||||
link="/sellers/contracts"
|
link={Pages.sellers.contract}
|
||||||
/>
|
/>
|
||||||
<SubMenuItem
|
<SubMenuItem
|
||||||
title={'آموزش ها'}
|
title={'آموزش ها'}
|
||||||
@@ -536,6 +536,8 @@ const SellersSubMenu: FC = () => {
|
|||||||
isActive={isActive('category')}
|
isActive={isActive('category')}
|
||||||
link={Pages.sellers.learningCategory}
|
link={Pages.sellers.learningCategory}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user