diff --git a/src/Pages/SubAdmin/AddModel.tsx b/src/Pages/SubAdmin/AddModel.tsx index 03472cb..ce5b260 100644 --- a/src/Pages/SubAdmin/AddModel.tsx +++ b/src/Pages/SubAdmin/AddModel.tsx @@ -1,80 +1,288 @@ -import { Button } from "../../components/ui/button" -import { DialogBody, DialogCloseTrigger, DialogContent, DialogFooter, DialogHeader, DialogRoot, DialogTitle, DialogTrigger } from "../../components/ui/dialog" -import { Field, Grid, Heading, Input, Stack, Text } from "@chakra-ui/react" -import { IoMdAdd } from "react-icons/io" -import { Checkbox } from "../../components/ui/checkbox" +import { useState } from "react"; +import { Button } from "../../components/ui/button"; +import { + DialogBody, + DialogCloseTrigger, + DialogContent, + DialogFooter, + DialogHeader, + DialogRoot, + DialogTitle, + DialogTrigger, +} from "../../components/ui/dialog"; +import { + Field, + Grid, + Heading, + Input, + Stack, + Text, +} from "@chakra-ui/react"; +import { IoMdAdd } from "react-icons/io"; +import { Checkbox } from "../../components/ui/checkbox"; +import { useCreateSubAdminPostMutation } from "../../Redux/Service/manage.subadmin.service"; +import { toaster } from "../../components/ui/toaster"; -function AddModel() { - return ( +function AddModel({ refetch }: { refetch: VoidFunction }) { + const [createSubAdminPost, { isLoading }] = useCreateSubAdminPostMutation(); - - - {/* */} - + const [formData, setFormData] = useState({ + firstName: "", + lastName: "", + dob: "", + gender: "", + email: "", + phone: "" + }); - + const [isOpen, setIsOpen] = useState(false); - - - Add Sub Admin Account - + const handleChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFormData(prev => ({ + ...prev, + [name]: value + })); + }; - - + const handleSubmit = async () => { + const { firstName, lastName, dob, gender, email, phone } = formData; + + if (!firstName || !lastName || !dob || !gender || !email || !phone) { + toaster.create({ + title: "Error", + description: "Please fill in all required fields", + type: "error", + }); + return; + } - - First Name - + const payload = { + // principal_type_xid: 4, + // principal_source_xid: 1, + // user_name: `${firstName} ${lastName}`, + first_name: firstName, + last_name: lastName, + date_of_birth: dob, + gender, + email_address: email, + phone_number: phone, + created_by: 1, + }; - Last Name - + try { + const response = await createSubAdminPost(payload).unwrap(); + + if (response.status === "success") { + toaster.create({ + title: "Success", + description: response.message || "Sub-admin added successfully", + type: "success", + }); + refetch(); + setIsOpen(false); + } + } catch (error: any) { + toaster.create({ + title: "Error", + description: error?.data?.message || "Failed to create sub-admin", + type: "error", + }); + } + }; - DOB - + return ( + setIsOpen(details.open)} + placement="center" + > + + + - Gender - - Permissions - - - Dashboard - Manage contact us - manage User - Manage CMS - Manage Post - Manage Reports - manage Sub-Admin - My profile - Manage Jobs - manage feedbacks - Manage community - Notification - - - - - - + + + + Add Sub Admin Account + + - - - + + + + + First Name + + - ) + + Last Name + + + + + DOB + + + + + Gender + + + + + Email + + + + + Phone Number + + + + + Permissions + + + + + + Dashboard + + + Manage contact us + + + Manage User + + + Manage CMS + + + Manage Post + + + Manage Reports + + + Manage Sub-Admin + + + My Profile + + + Manage Jobs + + + Manage Feedbacks + + + Manage Community + + + Notification + + + + + + + + + + + + + ); } -export default AddModel \ No newline at end of file +export default AddModel; diff --git a/src/Redux/Service/faqs.service.ts b/src/Redux/Service/faqs.service.ts index 332b87c..2d72f23 100644 --- a/src/Redux/Service/faqs.service.ts +++ b/src/Redux/Service/faqs.service.ts @@ -69,6 +69,7 @@ export const faqs = createApi({ body: { id, is_active }, }), }), + deleteFaqPost: builder.mutation<{ status: string; message: string }, { id: number }>({ query: ({ id }) => ({ diff --git a/src/Redux/Service/manage.subadmin.service.ts b/src/Redux/Service/manage.subadmin.service.ts index d10fbe6..a975d62 100644 --- a/src/Redux/Service/manage.subadmin.service.ts +++ b/src/Redux/Service/manage.subadmin.service.ts @@ -40,7 +40,6 @@ interface ApiResponse { data: PaginatedData; } - // export type SubAdminPost = { // id: number; // first_name: string, @@ -80,11 +79,30 @@ interface SubAdminView { data: SubAdmin[]; } +interface CreateSubAdminPayload { + principal_type_xid: number; + principal_source_xid: number; + user_name: string; + first_name: string; + last_name: string; + date_of_birth: string; + gender: string; + email_address: string; + phone_number: string; + created_by: number; +} + +interface CreateSubAdminResponse { + status: string; + status_code: number; + message: string; + data: UserData; +} export const manageSubAdmin = createApi({ reducerPath: "manageSubAdmin", baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling - tagTypes: ['SubAdmin'], + tagTypes: ["SubAdmin"], endpoints: (builder) => ({ createFaqPost: builder.mutation>({ query: (data) => ({ @@ -94,11 +112,11 @@ export const manageSubAdmin = createApi({ }), }), getSubAdmin: builder.query({ - query: () => `/sub-admin` + query: () => `/sub-admin`, }), viewSubAdmin: builder.query({ - query: (id) => `/sub-admin-view/${id}` + query: (id) => `/sub-admin-view/${id}`, }), updateSubAdmin: builder.mutation({ @@ -109,6 +127,15 @@ export const manageSubAdmin = createApi({ }), }), + createSubAdminPost: builder.mutation({ + query: (data) => ({ + url: "/sub-admin-create", + method: "POST", + body: data, + }), + invalidatesTags: ["SubAdmin"], // Add this to invalidate cache + }), + faqToggle: builder.mutation({ query: ({ id, is_active }) => ({ url: `/faq-status`, @@ -131,10 +158,11 @@ export const { useLazyViewSubAdminQuery, useUpdateSubAdminMutation, useDeleteSubAdminPostMutation, + useCreateSubAdminPostMutation } = manageSubAdmin; export type Post = { id: number; title: string; body: string; -}; \ No newline at end of file +};