diff --git a/src/pages/theme/Values.tsx b/src/pages/theme/Values.tsx
index 2d373bd..6253add 100644
--- a/src/pages/theme/Values.tsx
+++ b/src/pages/theme/Values.tsx
@@ -1,15 +1,18 @@
-import { type FC } from 'react'
+import { type FC, useState } from 'react'
import { useGetThemeValues } from './hooks/useThemeData'
import { useParams } from 'react-router-dom'
import PageTitle from '@/components/PageTitle'
import Td from '@/components/Td'
-import { Eye } from 'iconsax-react'
+import { Eye, Add } from 'iconsax-react'
import TrashWithConfrim from '@/components/TrashWithConfrim'
import { toast } from 'react-toastify'
+import Button from '@/components/Button'
+import CreateThemeValueModal from './components/CreateThemeValueModal'
const Values: FC = () => {
const { id } = useParams()
const { data, isLoading } = useGetThemeValues(id!)
+ const [isModalOpen, setIsModalOpen] = useState(false)
if (isLoading) {
return
در حال بارگذاری...
@@ -19,7 +22,18 @@ const Values: FC = () => {
return (
-
+
+
+
+
{themeInfo && (
@@ -78,6 +92,14 @@ const Values: FC = () => {
+
+ {id && (
+
setIsModalOpen(false)}
+ themeId={id}
+ />
+ )}
)
}
diff --git a/src/pages/theme/components/CreateThemeValueModal.tsx b/src/pages/theme/components/CreateThemeValueModal.tsx
new file mode 100644
index 0000000..6a49988
--- /dev/null
+++ b/src/pages/theme/components/CreateThemeValueModal.tsx
@@ -0,0 +1,114 @@
+import { type FC } from 'react'
+import { useFormik } from 'formik'
+import * as Yup from 'yup'
+import DefaulModal from '@/components/DefaulModal'
+import Input from '@/components/Input'
+import Button from '@/components/Button'
+import { useCreateThemeValue } from '../hooks/useThemeData'
+import { extractErrorMessage } from '@/helpers/utils'
+import { toast } from 'react-toastify'
+import { TickCircle } from 'iconsax-react'
+import type { CreateThemeValueType } from '../type/Types'
+
+interface Props {
+ open: boolean
+ close: () => void
+ themeId: string
+}
+
+const CreateThemeValueModal: FC = ({ open, close, themeId }) => {
+ const { mutate: createThemeValue, isPending } = useCreateThemeValue()
+
+ const formik = useFormik>({
+ initialValues: {
+ name: '',
+ value: '',
+ },
+ validationSchema: Yup.object({
+ name: Yup.string().required('نام الزامی است'),
+ value: Yup.string().required('مقدار الزامی است'),
+ }),
+ onSubmit: (values) => {
+ createThemeValue(
+ {
+ theme: themeId,
+ name: values.name,
+ value: values.value,
+ },
+ {
+ onSuccess: () => {
+ toast.success('مقدار تم با موفقیت ایجاد شد')
+ formik.resetForm()
+ close()
+ },
+ onError: (error) => {
+ toast.error(extractErrorMessage(error))
+ },
+ }
+ )
+ },
+ })
+
+ const handleClose = () => {
+ formik.resetForm()
+ close()
+ }
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+ )
+}
+
+export default CreateThemeValueModal
+
diff --git a/src/pages/theme/hooks/useThemeData.ts b/src/pages/theme/hooks/useThemeData.ts
index e32dd8f..009cff6 100644
--- a/src/pages/theme/hooks/useThemeData.ts
+++ b/src/pages/theme/hooks/useThemeData.ts
@@ -56,3 +56,13 @@ export const useGetThemeValues = (id: string) => {
enabled: !!id,
});
};
+
+export const useCreateThemeValue = () => {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: api.createThemeValue,
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ["theme-values"] });
+ },
+ });
+};
diff --git a/src/pages/theme/service/ThemeService.ts b/src/pages/theme/service/ThemeService.ts
index b1eaa8f..31fd37a 100644
--- a/src/pages/theme/service/ThemeService.ts
+++ b/src/pages/theme/service/ThemeService.ts
@@ -4,6 +4,7 @@ import type {
GetThemesResponseType,
GetThemeByIdResponseType,
GetThemeValuesResponseType,
+ CreateThemeValueType,
} from "../type/Types";
export const getThemes = async (): Promise => {
@@ -48,3 +49,26 @@ export const getThemeValues = async (
);
return data;
};
+
+export const createThemeValue = async (params: CreateThemeValueType) => {
+ const { data } = await axios.post(`/admin/category/theme-value`, params);
+ return data;
+};
+
+export const updateThemeValue = async (
+ id: string,
+ params: CreateThemeValueType
+) => {
+ const { data } = await axios.put(
+ `/admin/category/theme-value/${id}/value`,
+ params
+ );
+ return data;
+};
+
+export const deleteThemeValue = async (id: string) => {
+ const { data } = await axios.delete(
+ `/admin/category/theme-value/${id}/value`
+ );
+ return data;
+};