diff --git a/src/config/Pages.ts b/src/config/Pages.ts index f640002..ba4589b 100644 --- a/src/config/Pages.ts +++ b/src/config/Pages.ts @@ -34,7 +34,12 @@ export const Pages = { list: "/criticisms/list", detail: "/ccriticisms/detail/", }, - learning: "/learning", + learning: { + list: "/learning/list", + detail: "/learning/detail/", + create: "/learning/create", + category: "/learning/category", + }, setting: "/setting", wallet: "/wallet", profile: "/profile", diff --git a/src/config/SideBarSubMenu.ts b/src/config/SideBarSubMenu.ts index d9c9209..ba3c2aa 100644 --- a/src/config/SideBarSubMenu.ts +++ b/src/config/SideBarSubMenu.ts @@ -4,4 +4,5 @@ export const SideBarItemHasSubMenu = [ "receipts", "users", "tickets", + "learning", ]; diff --git a/src/langs/fa.json b/src/langs/fa.json index a7c22e0..a5e9ca7 100644 --- a/src/langs/fa.json +++ b/src/langs/fa.json @@ -425,7 +425,10 @@ "no_select_file": "هیچ فایلی انتخاب نشده است", "attachment": "فایل های ضمیمه", "learning": { - "learning": "آموزش" + "learning": "آموزش", + "learnings": "آموزش ها", + "new_learning": "افزودن آموزش", + "category_learning": "دسته بندی آموزش" }, "setting": { "setting": "تنظیمات", diff --git a/src/pages/learning/Category.tsx b/src/pages/learning/Category.tsx new file mode 100644 index 0000000..3e94302 --- /dev/null +++ b/src/pages/learning/Category.tsx @@ -0,0 +1,74 @@ +import { FC, useState } from 'react' +import { useTranslation } from 'react-i18next' +import Td from '../../components/Td' +import PageLoading from '../../components/PageLoading' +import Pagination from '../../components/Pagination' +import { useGetCategory } from './hooks/useLearningData' +import { CategoryLearningType } from './types/LearningTypes' +import CreateCategory from './components/CreateCategory' + + +const LearningCategory: FC = () => { + + const { t } = useTranslation('global') + const [page, setPage] = useState(1) + const getCategory = useGetCategory() + + return ( +
+
+ {t('service.cateory_services')} +
+ +
+
+ +
+ { + getCategory.isPending ? +
+ +
+ : +
+ + + + + + + { + getCategory.data?.data?.categories?.map((item: CategoryLearningType) => { + return ( + + + ) + }) + } + +
+ +
+ +
+
+ +
+
+ } + + +
+
+ + +
+
+ ) +} + +export default LearningCategory \ No newline at end of file diff --git a/src/pages/learning/components/CreateCategory.tsx b/src/pages/learning/components/CreateCategory.tsx new file mode 100644 index 0000000..b7a8e67 --- /dev/null +++ b/src/pages/learning/components/CreateCategory.tsx @@ -0,0 +1,81 @@ +import { FC } from 'react' +import { useTranslation } from 'react-i18next' +import Input from '../../../components/Input' +import Button from '../../../components/Button' +import { TickCircle } from 'iconsax-react' +import * as Yup from 'yup' +import { useFormik } from 'formik' +import { toast } from 'react-toastify' +import { ErrorType } from '../../../helpers/types' +import { CreateCategoryLearningType } from '../types/LearningTypes' +import { useCreateCategory, useGetCategory } from '../hooks/useLearningData' + +const CreateCategory: FC = () => { + + const { t } = useTranslation('global') + const createCategory = useCreateCategory() + const getCategory = useGetCategory() + + const formik = useFormik({ + initialValues: { + name: '' + }, + validationSchema: Yup.object({ + name: Yup.string().required(t('errors.required')), + }), + onSubmit: (values) => { + + createCategory.mutate(values, { + onSuccess: () => { + formik.resetForm() + getCategory.refetch() + toast.success(t('success')) + }, + onError: (error: ErrorType) => { + toast.error(error?.response?.data?.error?.message[0]) + } + }) + } + }) + + return ( +
+
+ {t('service.add_category')} +
+ + +
+ +
+ + + + + +
+ +
+
+ ) +} + +export default CreateCategory \ No newline at end of file diff --git a/src/pages/learning/hooks/useLearningData.ts b/src/pages/learning/hooks/useLearningData.ts new file mode 100644 index 0000000..2638dc1 --- /dev/null +++ b/src/pages/learning/hooks/useLearningData.ts @@ -0,0 +1,17 @@ +import { useMutation, useQuery } from "@tanstack/react-query"; +import * as api from "../service/LearningService"; +import { CreateCategoryLearningType } from "../types/LearningTypes"; + +export const useGetCategory = () => { + return useQuery({ + queryKey: ["learning-category"], + queryFn: api.getCategory, + }); +}; + +export const useCreateCategory = () => { + return useMutation({ + mutationFn: (variables: CreateCategoryLearningType) => + api.createCategory(variables), + }); +}; diff --git a/src/pages/learning/service/LearningService.ts b/src/pages/learning/service/LearningService.ts new file mode 100644 index 0000000..a039a0f --- /dev/null +++ b/src/pages/learning/service/LearningService.ts @@ -0,0 +1,12 @@ +import axios from "../../../config/axios"; +import { CreateCategoryLearningType } from "../types/LearningTypes"; + +export const getCategory = async () => { + const { data } = await axios.get(`/learnings/category`); + return data; +}; + +export const createCategory = async (params: CreateCategoryLearningType) => { + const { data } = await axios.post(`/learnings/category`, params); + return data; +}; diff --git a/src/pages/learning/types/LearningTypes.ts b/src/pages/learning/types/LearningTypes.ts new file mode 100644 index 0000000..b4f67c7 --- /dev/null +++ b/src/pages/learning/types/LearningTypes.ts @@ -0,0 +1,8 @@ +export type CreateCategoryLearningType = { + name: string; +}; + +export type CategoryLearningType = { + id: number; + name: string; +}; diff --git a/src/router/Main.tsx b/src/router/Main.tsx index 69bf0aa..f612272 100644 --- a/src/router/Main.tsx +++ b/src/router/Main.tsx @@ -49,6 +49,7 @@ import CreateBankCard from '../pages/cardBank/Create' import CardBankList from '../pages/cardBank/List' import EditBankCard from '../pages/cardBank/Edit' import PaymentList from '../pages/payment/List' +import LearningCategory from '../pages/learning/Category' const MainRouter: FC = () => { @@ -94,7 +95,8 @@ const MainRouter: FC = () => { } /> } /> } /> - } /> + } /> + } /> } /> } /> } /> diff --git a/src/shared/SideBar.tsx b/src/shared/SideBar.tsx index 7bff134..4d1d0b0 100644 --- a/src/shared/SideBar.tsx +++ b/src/shared/SideBar.tsx @@ -14,6 +14,7 @@ import ReceiptSubMenu from './components/ReceiptSubMenu' import CustomerSubMenu from './components/CustomerSubMenu' import TicketSubMenu from './components/TicketSubMenu' import UsersSubMenu from './components/UsersSubMenu' +import LearningSubMenu from './components/LearningSubMenu' const SideBar: FC = () => { @@ -213,7 +214,7 @@ const SideBar: FC = () => { icon={} title={t('sidebar.learning')} isActive={isActive('learning')} - link={Pages.learning} + link={Pages.learning.list} /> @@ -272,7 +273,9 @@ const SideBar: FC = () => { : subMenuName === 'users' ? - : null + : subMenuName === 'learning' ? + + : null } } diff --git a/src/shared/components/LearningSubMenu.tsx b/src/shared/components/LearningSubMenu.tsx new file mode 100644 index 0000000..663e74a --- /dev/null +++ b/src/shared/components/LearningSubMenu.tsx @@ -0,0 +1,52 @@ +import { Teacher } from 'iconsax-react' +import { FC } from 'react' +import { useTranslation } from 'react-i18next' +import SubMenuItem from './SubMenuItem' +import { useLocation } from 'react-router-dom' +import { Pages } from '../../config/Pages' + +const LearningSubMenu: FC = () => { + + const { t } = useTranslation('global') + const location = useLocation() + + const isActive = (name: string) => { + return location.pathname.includes(name) + } + + return ( +
+
+ +
+ {t('sidebar.learning')} +
+
+ +
+ + + +
+ +
+ ) +} + +export default LearningSubMenu \ No newline at end of file