diff --git a/src/Layouts/DefaultLayout.tsx b/src/Layouts/DefaultLayout.tsx index 5558658..92581ab 100644 --- a/src/Layouts/DefaultLayout.tsx +++ b/src/Layouts/DefaultLayout.tsx @@ -12,9 +12,10 @@ import { useDispatch } from "react-redux"; import GlobalStateContext from "../Contexts/GlobalStateContext"; import { useLogOutMutation } from "../Redux/Service/apiSlice"; import ProgressBar from "../components/ProgressBar/ProgressBar"; +import { useGetProfileQuery } from "../Redux/Service/profile.password"; const DefaultLayout: FC<{ children: React.ReactNode }> = ({ children }) => { - + const { data } = useGetProfileQuery() const dispatch = useDispatch() const navigate = useNavigate() const location = useLocation() @@ -25,20 +26,20 @@ const DefaultLayout: FC<{ children: React.ReactNode }> = ({ children }) => { throw new Error('App must be used within a GlobalStateProvider'); } const { setIsAuthenticate, isBarLoading } = context; - const [ logOutAdmin ] = useLogOutMutation() + const [logOutAdmin] = useLogOutMutation() // Logout function const handleLogout = async () => { try { // ✅ Call mutation and wait for the response - const res = await logOutAdmin().unwrap(); + const res = await logOutAdmin().unwrap(); console.log("Logout Success:", res); - + // ✅ Clear local storage & update authentication state dispatch(logout()); - localStorage.removeItem("token"); - setIsAuthenticate(false); + localStorage.removeItem("token"); + setIsAuthenticate(false); // ✅ Redirect to login page navigate("/login"); } catch (error) { @@ -48,43 +49,43 @@ const DefaultLayout: FC<{ children: React.ReactNode }> = ({ children }) => { return ( - - - - - - - - - {nav?.map(({ title, path, Icon, type, children, initPath }, index) => type === 'single' ? - {title} : - - - navigate(path||'')} gap={0} style={{ cursor: 'pointer', borderRadius: '8px', padding: '5px', width: '100%', display: 'flex', alignItems: 'center', border: '1px solid #ffffff', backgroundColor:'#fff',color:'#000', fontSize: '14px', }}> {title} - {children?.map(({ title, path, Icon }, index) => navigate(path)} style={{ marginTop: 6, cursor: 'pointer', borderRadius: '8px', padding: '6px', width: '100%', display: 'flex', alignItems: 'center', gap: 6, border: '1px solid #ffffff', backgroundColor:'#fff',color:'#919198' }} > {title})} - - )} - - - Logout - - - - - - - - navigate('/profile')} > - - - Ritesh Pandey - ritesh.pandey@wdimails.com - + + + + + + - - {children} - - + + {nav?.map(({ title, path, Icon, type, children, initPath }, index) => type === 'single' ? + {title} : + + + navigate(path || '')} gap={0} style={{ cursor: 'pointer', borderRadius: '8px', padding: '5px', width: '100%', display: 'flex', alignItems: 'center', border: '1px solid #ffffff', backgroundColor: '#fff', color: '#000', fontSize: '14px', }}> {title} + {children?.map(({ title, path, Icon }, index) => navigate(path)} style={{ marginTop: 6, cursor: 'pointer', borderRadius: '8px', padding: '6px', width: '100%', display: 'flex', alignItems: 'center', gap: 6, border: '1px solid #ffffff', backgroundColor: '#fff', color: '#919198' }} > {title})} + + )} + + + Logout + + + + + + + + navigate('/profile')} > + + + {`${data?.data?.first_name.charAt(0).toUpperCase()}${data?.data.first_name.slice(1)}`} + {data?.data?.phone_number} + + + + {children} + + ); }; diff --git a/src/Pages/ManageCMS/FAQ/FAQ.tsx b/src/Pages/ManageCMS/FAQ/FAQ.tsx index 504b263..94f54f8 100644 --- a/src/Pages/ManageCMS/FAQ/FAQ.tsx +++ b/src/Pages/ManageCMS/FAQ/FAQ.tsx @@ -53,7 +53,8 @@ const tableHeadRow = [ // ]; const FAQ = () => { - const { data, refetch, isLoading, isFetching } = useGetFaqQuery() + const [currentPage, setCurrentPage] = useState(1); + const { data, refetch, isLoading, isFetching } = useGetFaqQuery(currentPage) const [localData, setLocalData] = useState([]); const [faqToggle] = useFaqToggleMutation() const [deleteFaqPost] = useDeleteFaqPostMutation() @@ -69,6 +70,10 @@ const FAQ = () => { } }, [data]); + const handlePageChange = (page: number) => { + setCurrentPage(page); + }; + const handleToggle = async (agencyId: number, currentStatus: string) => { const newStatus = currentStatus === '1' ? '0' : '1'; @@ -129,7 +134,7 @@ const FAQ = () => { const managepost = filteredData?.flatMap((agency: FaqData, index: number) => agency.translations.map((translation: any) => ({ 'id': translation.id, - "Sr. No": index + 1, + "Sr. No": (currentPage - 1) * (data?.data.per_page ?? 0) + index + 1, "Question": translation.question, "Answer": translation.answer, 'Category': agency.principal_type_xid === 2 ? "Job Seeker" : "Recruiter", @@ -178,7 +183,7 @@ const FAQ = () => { py={0} px={3} > - + ) } @@ -208,13 +213,18 @@ const FAQ = () => { {isFetching && } {!isLoading && !data?.data ? ( - + ) : ()} diff --git a/src/Pages/MasterModule/AgencyMaster/AgencyMaster.tsx b/src/Pages/MasterModule/AgencyMaster/AgencyMaster.tsx index 451660b..b2e8025 100644 --- a/src/Pages/MasterModule/AgencyMaster/AgencyMaster.tsx +++ b/src/Pages/MasterModule/AgencyMaster/AgencyMaster.tsx @@ -47,7 +47,8 @@ const tableHeadRow = [ // ]; const AgencyMaster = () => { - const { data, refetch } = useGetAgencyMasterQuery() + const [currentPage, setCurrentPage] = useState(1); + const { data, refetch } = useGetAgencyMasterQuery(currentPage) const [agencyMasterToggle] = useAgencyMasterToggleMutation() const [localData, setLocalData] = useState([]); const [searchTerm, setSearchTerm] = useState(""); @@ -72,13 +73,17 @@ const AgencyMaster = () => { } }; + const handlePageChange = (page: number) => { + setCurrentPage(page); + }; + const filteredData = localData?.filter((agency) => agency?.name.toLowerCase().includes(searchTerm.toLowerCase()) ); const managepost = filteredData?.map((agency: any, index: number) => ({ 'id': agency.id, - "Sr. No": index + 1, + "Sr. No": (currentPage - 1) * (data?.data.per_page ?? 0) + index + 1, "Agency Name": agency.name, "RC no.": agency.rc_number, "State": agency.state, @@ -162,8 +167,13 @@ const AgencyMaster = () => { sortableColumns={["Name", "Registration Date "]} tableHeadRow={tableHeadRow} data={managepost || []} - paginationData={data?.data.data} - refetch={refetch} + paginationData={{ + current_page: data?.data.current_page || 1, + last_page: data?.data.last_page || 1, + per_page: data?.data.per_page || 10, + total: data?.data.total || 0 + }} + onPageChange={handlePageChange} /> diff --git a/src/Pages/MasterModule/Country/Country.tsx b/src/Pages/MasterModule/Country/Country.tsx index 96afe6e..9b0c5a1 100644 --- a/src/Pages/MasterModule/Country/Country.tsx +++ b/src/Pages/MasterModule/Country/Country.tsx @@ -1,11 +1,12 @@ -import { Box, HStack, Input, Text } from "@chakra-ui/react"; +import { Box, HStack, Text } from "@chakra-ui/react"; import MainFrame from "../../../components/MainFrame" -import { InputGroup } from "../../../components/ui/input-group"; -import { LuSearch } from "react-icons/lu"; import DataTable from "../../../components/DataTable"; import { Switch } from "../../../components/ui/switch"; import CountryAddModel from "./CountryAddModel"; import EditCountryModel from "./EditCountryModel"; +import { CountryData, useCountryToggleMutation, useGetCountryMasterQuery } from "../../../Redux/Service/country.master"; +import { useEffect, useState } from "react"; +import SearchComponent from "../../../components/SearchComponent"; @@ -15,25 +16,89 @@ const tableHeadRow = [ "Sr. No", "Title", "Action" - + ]; -const managepost: any[] = [ - ...Array.from({ length: 12 }, (_, i) => ({ - "Sr. No": i + 1, - "Title": "Lorem Ipsum", +// const managepost: any[] = [ +// ...Array.from({ length: 12 }, (_, i) => ({ +// "Sr. No": i + 1, +// "Title": "Lorem Ipsum", +// "Action": ( +// +// +// +// +// +// +// ), +// })), +// ]; + +const Country = () => { + const [currentPage, setCurrentPage] = useState(1); + const { data, refetch } = useGetCountryMasterQuery(currentPage) + const [countryToggle] = useCountryToggleMutation() + const [localData, setLocalData] = useState([]); + const [searchTerm, setSearchTerm] = useState(""); + console.log("Country Data", data?.data.data) + + useEffect(() => { + if (data) { + setLocalData(data?.data.data); + } + }, [data]); + + const handlePageChange = (page: number) => { + setCurrentPage(page); + }; + + const filteredData = localData?.filter((agency) => { + const searchLower = searchTerm.toLowerCase(); + const countryName = agency.en_name?.toLowerCase().includes(searchLower); + const capitalName = agency.capital?.toLowerCase().includes(searchLower); + return countryName || capitalName; + }); + + const handleToggle = async (agencyId: number, currentStatus: string) => { + const newStatus = currentStatus === '1' ? '0' : '1'; + + setLocalData((prevData) => + prevData.map((agency) => + agency.id === agencyId ? { ...agency, is_active: newStatus } : agency + ) + ); + + try { + await countryToggle({ id: agencyId, is_active: newStatus }).unwrap(); + refetch() + } catch (error) { + console.error("Error updating privacy policy:", error); + setLocalData((prevData) => + prevData.map((agency) => + agency.id === agencyId ? { ...agency, is_active: currentStatus } : agency + ) + ); + } + } + + const managepost = filteredData?.flatMap((agency: CountryData, index: number) => ({ + "Sr. No": (currentPage - 1) * (data?.data.per_page ?? 0) + index + 1, + "Title": agency.en_name, "Action": ( - + - + handleToggle(agency.id, agency.is_active)} + /> ), - })), -]; + })) -const Country = () => { return ( @@ -46,11 +111,11 @@ const Country = () => { px={3} > - Country + Country - } @@ -69,7 +134,14 @@ const Country = () => { bgColor={'#EEEEEE'} ps={8} /> - + */} + { + setSearchTerm(value); + setCurrentPage(1); + }} + /> {/* */} @@ -78,8 +150,15 @@ const Country = () => { sortableColumns={["Name", "Registration Date "]} tableHeadRow={tableHeadRow} data={managepost} + paginationData={{ + current_page: data?.data.current_page || 1, + last_page: data?.data.last_page || 1, + per_page: data?.data.per_page || 10, + total: data?.data.total || 0 + }} + onPageChange={handlePageChange} /> - + ) } diff --git a/src/Pages/MasterModule/Country/CountryAddModel.tsx b/src/Pages/MasterModule/Country/CountryAddModel.tsx index 0ba1064..b2a7834 100644 --- a/src/Pages/MasterModule/Country/CountryAddModel.tsx +++ b/src/Pages/MasterModule/Country/CountryAddModel.tsx @@ -2,55 +2,201 @@ import { DialogBody, DialogCloseTrigger, DialogContent, DialogFooter, DialogHead import { Field, Input, Stack, Text } from "@chakra-ui/react" import { IoMdAdd } from "react-icons/io" import { Button } from "../../../components/ui/button" +import { useState } from "react"; +import { PostCountry, useCreateCountryPostMutation } from "../../../Redux/Service/country.master"; +import { Toaster, toaster } from "../../../components/ui/toaster"; function CountryAddModel() { - - return ( + const [createCountryPost] = useCreateCountryPostMutation() + const [isOpen, setIsOpen] = useState(false); + const [countryName, setCountryName] = useState({ + en_name: '', + country_code: '', + phonecode: '', + capital: '', + currency: '', + currency_name: '', + currency_symbol: '', + }); - - - {/* */} - - - - - - - Add - - - - - - - Country - - - - - - - - - - - + + + + + Add + + + + + + + Country + setCountryName({ ...countryName, en_name: e.target.value })} + /> + + Country Code + setCountryName({ ...countryName, country_code: e.target.value })} + /> + + Phone Code + setCountryName({ ...countryName, phonecode: e.target.value })} + /> + Capital + setCountryName({ ...countryName, capital: e.target.value })} + /> + Currency + setCountryName({ ...countryName, currency: e.target.value })} + /> + Currency name + setCountryName({ ...countryName, currency_name: e.target.value })} + /> + Currency Symbol + setCountryName({ ...countryName, currency_symbol: e.target.value })} + /> + + + + + + + + + + + + + ) } diff --git a/src/Pages/MasterModule/Country/EditCountryModel.tsx b/src/Pages/MasterModule/Country/EditCountryModel.tsx index 422c9e8..2b4f47e 100644 --- a/src/Pages/MasterModule/Country/EditCountryModel.tsx +++ b/src/Pages/MasterModule/Country/EditCountryModel.tsx @@ -8,59 +8,153 @@ import { DialogTitle, DialogTrigger, } from "../../../components/ui/dialog"; -import { Field, Input, Span, Stack } from "@chakra-ui/react"; +import { Field, Input, Stack } from "@chakra-ui/react"; import { Button } from "../../../components/ui/button"; import Edit from "../../../components/ActionIcons/Edit"; +import { useUpdateCountryMutation } from "../../../Redux/Service/country.master"; +import { Toaster, toaster } from "../../../components/ui/toaster"; +import { useEffect, useState } from "react"; + +export interface EditCountryModelProps { + id?: number; + en_name?: string; + hi_name?: string; + mr_name?: string; + te_name?: string; + ta_name?: string; + bn_name?: string; + or_name?: string; + country_code?: string; + phonecode?: string; + capital?: string; + currency?: string; + currency_name?: string; + currency_symbol?: string; +} + + + + +function EditCountryModel({ rowData, refetch }: { rowData: EditCountryModelProps, refetch: VoidFunction }) { + const [updateCountry] = useUpdateCountryMutation() + const [editData, setEditData] = useState(rowData) + const [isOpen, setIsOpen] = useState(false); + + useEffect(() => { + if(rowData){ + setEditData(rowData) + } + }, [rowData]) + + + const handleOpenModal = () => { + setIsOpen(true); + }; + + const handleSubmit = async () => { + if (editData?.en_name === '') { + toaster.create({ + title: "Error", + description: "Input fields cannot be empty", + type: "error", + }); + return; + } + + // Only en_name is editable, so we only need to send that in the payload. + const payload = { + id: rowData?.id, + en_name: editData?.en_name, + country_code: rowData?.country_code, + phonecode: rowData?.phonecode, + capital: rowData?.capital, + currency: rowData?.currency, + currency_name: rowData?.currency_name, + currency_symbol: rowData?.currency_symbol, + }; + + // console.log('payload', payload) + + try { + const response = await updateCountry(payload).unwrap(); + if (response?.status === "success") { + toaster.create({ + title: "Success", + description: "Country updated successfully", + type: "success", + }); + setIsOpen(false); + refetch() + } else { + toaster.create({ + title: "Error", + description: "Failed to update Country", + type: "error", + }); + } + } catch (error) { + console.error("Error updating template:", error); + // alert("Failed to update template"); + toaster.create({ + title: "Error", + description: "Something went wrong", + type: "error", + }); + } + }; + -function EditCountryModel() { return ( - - - - + <> + setIsOpen(open)}> + + + - - - - Edit - - + + + + Edit + + + + + + + Country + + setEditData({ ...editData, en_name: e.target.value })} + bgColor="#EEEEEE" + color="black" + border="none" + pl={1} + fontSize="12px" + height="30px" + /> + + + + + + - - - - - Country - - - - - - - - - - - - + + + + + ); } diff --git a/src/Pages/MasterModule/IndustryMaster/IndustryMasterList.tsx b/src/Pages/MasterModule/IndustryMaster/IndustryMasterList.tsx index ccd9501..76f2231 100644 --- a/src/Pages/MasterModule/IndustryMaster/IndustryMasterList.tsx +++ b/src/Pages/MasterModule/IndustryMaster/IndustryMasterList.tsx @@ -1,13 +1,14 @@ -import { Box, HStack, Input, Text } from "@chakra-ui/react"; +import { Box, HStack, Text } from "@chakra-ui/react"; import MainFrame from "../../../components/MainFrame" -import { InputGroup } from "../../../components/ui/input-group"; -import { LuSearch } from "react-icons/lu"; +// import { InputGroup } from "../../../components/ui/input-group"; +// import { LuSearch } from "react-icons/lu"; import DataTable from "../../../components/DataTable"; import { Switch } from "../../../components/ui/switch"; import { useEffect, useState } from "react"; import { useGetIndustryMasterQuery, useIndustryMasterToggleMutation } from "../../../Redux/Service/industry.master.service"; import EditIndustryMaster from "./EditIndustryMaster"; import AddIndustryMaster from "./AddIndustryMaster"; +import SearchComponent from "../../../components/SearchComponent"; // table data @@ -42,9 +43,11 @@ const tableHeadRow = [ // ]; const IndustryMasterList = () => { - const { data, refetch } = useGetIndustryMasterQuery() + const [currentPage, setCurrentPage] = useState(1); + const { data, refetch } = useGetIndustryMasterQuery(currentPage) const [industryMasterToggle] = useIndustryMasterToggleMutation() const [localData, setLocalData] = useState([]); + const [searchTerm, setSearchTerm] = useState(""); useEffect(() => { if (data?.data?.data) { @@ -52,6 +55,10 @@ const IndustryMasterList = () => { } }, [data]); + const handlePageChange = (page: number) => { + setCurrentPage(page); + }; + const handleToggle = async (agencyId: string, currentStatus: number) => { const newStatus = currentStatus ? 0 : 1; setLocalData((prevData) => @@ -72,9 +79,15 @@ const IndustryMasterList = () => { } }; - const managepost = localData?.map((agency: any, index: number) => ({ + const filteredData = localData?.filter((agency) => { + const searchLower = searchTerm.toLowerCase(); + const title = agency.en_name?.toLowerCase().includes(searchLower); + return title; + }); + + const managepost = filteredData?.map((agency: any, index: number) => ({ 'id': agency.id, - "Sr. No": index + 1, + "Sr. No": (currentPage - 1) * (data?.data.per_page ?? 0) + index + 1, "Title": agency.en_name, "is_active": agency.is_active, "Action": ( @@ -93,11 +106,11 @@ const IndustryMasterList = () => { ), })); - useEffect(() => { - console.log("Fetched data:", data); - console.log("Local data:", localData); - console.log("Managepost data:", managepost); - }, [data, localData, managepost]); + // useEffect(() => { + // console.log("Fetched data:", data); + // console.log("Local data:", localData); + // console.log("Managepost data:", managepost); + // }, [data, localData, managepost]); return ( @@ -115,37 +128,29 @@ const IndustryMasterList = () => { - - } - color={"#000"} - > - - + { + setSearchTerm(value); + setCurrentPage(1); + }} + /> {/* */} {/* */} - + diff --git a/src/Pages/MasterModule/JobType/JobType.tsx b/src/Pages/MasterModule/JobType/JobType.tsx index 81ffb2f..d4757e8 100644 --- a/src/Pages/MasterModule/JobType/JobType.tsx +++ b/src/Pages/MasterModule/JobType/JobType.tsx @@ -1,13 +1,14 @@ -import { Box, HStack, Input, Text } from "@chakra-ui/react"; +import { Box, HStack, Text } from "@chakra-ui/react"; import MainFrame from "../../../components/MainFrame" -import { InputGroup } from "../../../components/ui/input-group"; -import { LuSearch } from "react-icons/lu"; +// import { InputGroup } from "../../../components/ui/input-group"; +// import { LuSearch } from "react-icons/lu"; import DataTable from "../../../components/DataTable"; import { Switch } from "../../../components/ui/switch"; import JobAddModel from "./JobAddModel"; import EditJobeModel from "./EditJobModel"; import { JobTypeData, useGetJobTypeQuery } from "../../../Redux/Service/job.type.service"; import { useEffect, useState } from "react"; +import SearchComponent from "../../../components/SearchComponent"; @@ -36,8 +37,10 @@ const tableHeadRow = [ // ]; const JobType = () => { - const { data, refetch } = useGetJobTypeQuery() + const [currentPage, setCurrentPage] = useState(1); + const { data, refetch } = useGetJobTypeQuery(currentPage) const [localData, setLocalData] = useState([]); + const [searchTerm, setSearchTerm] = useState(""); // const [templateMasterToggle] = useTemplateMasterToggleMutation() console.log('DATA', data?.data.data); @@ -48,6 +51,16 @@ const JobType = () => { } }, [data]); + const handlePageChange = (page: number) => { + setCurrentPage(page); + }; + + const filteredData = localData?.filter((agency) => { + const searchLower = searchTerm.toLowerCase(); + const title = agency.en_name?.toLowerCase().includes(searchLower); + return title; + }); + // const handleToggle = async (agencyId: string, currentStatus: number) => { // const newStatus = currentStatus ? 0 : 1; // setLocalData((prevData) => @@ -69,8 +82,8 @@ const JobType = () => { // }; - const managepost = localData?.map((agency: JobTypeData, index: number) => ({ - 'id': agency.id, + const managepost = filteredData?.map((agency: JobTypeData, index: number) => ({ + 'id': (currentPage - 1) * (data?.data.per_page ?? 0) + index + 1, "Sr. No": index + 1, "Title": agency.en_name, @@ -106,26 +119,13 @@ const JobType = () => { - - } - color={"#000"} - > - - + { + setSearchTerm(value); + setCurrentPage(1); + }} + /> {/* */} @@ -134,8 +134,13 @@ const JobType = () => { sortableColumns={["Name", "Registration Date "]} tableHeadRow={tableHeadRow} data={managepost} - paginationData={data?.data} - refetch={refetch} + paginationData={{ + current_page: data?.data.current_page || 1, + last_page: data?.data.last_page || 1, + per_page: data?.data.per_page || 10, + total: data?.data.total || 0 + }} + onPageChange={handlePageChange} /> diff --git a/src/Pages/MasterModule/TemplateMaster/TemplateMaster.tsx b/src/Pages/MasterModule/TemplateMaster/TemplateMaster.tsx index 38fe32b..031a0a6 100644 --- a/src/Pages/MasterModule/TemplateMaster/TemplateMaster.tsx +++ b/src/Pages/MasterModule/TemplateMaster/TemplateMaster.tsx @@ -45,7 +45,8 @@ const tableHeadRow = [ // ]; const TemplateMaster = () => { - const { data, refetch } = useGetTemplateMasterQuery() + const [currentPage, setCurrentPage] = useState(1); + const { data, refetch } = useGetTemplateMasterQuery(currentPage) const [localData, setLocalData] = useState([]); const [templateMasterToggle] = useTemplateMasterToggleMutation(); const [searchTerm, setSearchTerm] = useState(""); @@ -57,6 +58,10 @@ const TemplateMaster = () => { } }, [data]); + const handlePageChange = (page: number) => { + setCurrentPage(page); + }; + const handleToggle = async (agencyId: string, currentStatus: number) => { const newStatus = currentStatus ? 0 : 1; setLocalData((prevData) => @@ -83,7 +88,7 @@ const TemplateMaster = () => { const managepost = filteredData?.map((agency: Template, index: number) => ({ 'id': agency.id, - "Sr. No": index + 1, + "Sr. No": (currentPage - 1) * (data?.data.per_page ?? 0) + index + 1, "Title": agency.post_template_translate.length > 0 ? agency.post_template_translate[0].title : "N/A", @@ -160,8 +165,13 @@ const TemplateMaster = () => { sortableColumns={["Name", "Registration Date "]} tableHeadRow={tableHeadRow} data={managepost} - paginationData={data?.data.data} - refetch={refetch} + paginationData={{ + current_page: data?.data.current_page || 1, + last_page: data?.data.last_page || 1, + per_page: data?.data.per_page || 10, + total: data?.data.total || 0 + }} + onPageChange={handlePageChange} /> diff --git a/src/Redux/Service/agency.master.module.service.ts b/src/Redux/Service/agency.master.module.service.ts index 8b29368..f96d017 100644 --- a/src/Redux/Service/agency.master.module.service.ts +++ b/src/Redux/Service/agency.master.module.service.ts @@ -70,8 +70,8 @@ export const agencyMasterModule = createApi({ }), }), - getAgencyMaster: builder.query({ - query: () => "/agency-master" + getAgencyMaster: builder.query({ + query: (page = 1) => `/agency-master?page=${page}` }), agencyMasterToggle: builder.mutation({ diff --git a/src/Redux/Service/country.master.ts b/src/Redux/Service/country.master.ts new file mode 100644 index 0000000..f70f360 --- /dev/null +++ b/src/Redux/Service/country.master.ts @@ -0,0 +1,110 @@ +import { createApi } from "@reduxjs/toolkit/query/react"; +import { baseQueryWithReauth } from "./apiSlice"; + +export interface CountryData { + id: number; + en_name: string; + hi_name: string; + mr_name: string; + te_name: string; + ta_name: string; + bn_name: string; + or_name: string; + country_code: string; + phonecode: string; + capital: string; + currency: string; + currency_name: string; + currency_symbol: string; + is_active: string; +} + +interface ApiResponse { + status: string; + status_code: number; + message: string; + data: { + current_page: number, + last_page: number, + total: number, + from: number, + per_page: number, + to: number, + data: CountryData[]; + }; +} + +export interface CountryEdit { + status: string; + status_code: number; + message: string; + data: CountryData[]; +} + + +export type PostCountry = { + en_name: string; + country_code: string; + phonecode: string; + capital: string; + currency: string; + currency_name: string; + currency_symbol: string; +}; + + +export const countryMaster = createApi({ + reducerPath: "countryMaster", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + createCountryPost: builder.mutation>({ + query: (data) => ({ + url: "/country-add", + method: "POST", + body: data, + }), + }), + // 🔹 GET: Fetch all posts + getCountryMaster: builder.query({ + query: (page = 1) => `/country-list?page=${page}`, + }), + + getCountryMasterEdit: builder.query({ + query: (id) => `/country-edit/${id}`, + }), + + updateCountry: builder.mutation({ + query: (updatedData) => ({ + url: "/country-update", + method: "POST", + body: updatedData, + }), + }), + + countryToggle: builder.mutation({ + query: ({ id, is_active }) => ({ + url: `/country-status`, + method: "POST", + body: { id, is_active }, + }), + }), + + // deleteFaqPost: builder.mutation<{ status: string; message: string }, { id: number }>({ + // query: ({ id }) => ({ + // url: `/faq-delete`, + // method: "POST", + // body: { id }, + // }), + // }), + + }), +}); + +export const { + useGetCountryMasterQuery, + useGetCountryMasterEditQuery, + useCreateCountryPostMutation, + useUpdateCountryMutation, + useCountryToggleMutation, + // useDeleteFaqPostMutation +} = countryMaster; \ No newline at end of file diff --git a/src/Redux/Service/faqs.service.ts b/src/Redux/Service/faqs.service.ts index 2577898..332b87c 100644 --- a/src/Redux/Service/faqs.service.ts +++ b/src/Redux/Service/faqs.service.ts @@ -23,6 +23,8 @@ interface ApiResponse { last_page: number, total: number, from: number, + per_page: number, + to: number, data: FaqData[]; }; } @@ -48,8 +50,8 @@ export const faqs = createApi({ }), }), // 🔹 GET: Fetch all posts - getFaq: builder.query({ - query: () => "/faq-list", + getFaq: builder.query({ + query: (page = 1) => `/faq-list?page=${page}`, }), updateFaq: builder.mutation({ diff --git a/src/Redux/Service/industry.master.service.ts b/src/Redux/Service/industry.master.service.ts index 76a5e76..d227bf8 100644 --- a/src/Redux/Service/industry.master.service.ts +++ b/src/Redux/Service/industry.master.service.ts @@ -61,8 +61,8 @@ export const industryMaster = createApi({ }), }), // 🔹 GET: Fetch all posts - getIndustryMaster: builder.query({ - query: () => "/industry-master-list", + getIndustryMaster: builder.query({ + query: (page = 1) => `/industry-master-list?page=${page}`, }), updateIndustryMaster: builder.mutation({ diff --git a/src/Redux/Service/job.type.service.ts b/src/Redux/Service/job.type.service.ts index 3d8c5a9..6aa7dd0 100644 --- a/src/Redux/Service/job.type.service.ts +++ b/src/Redux/Service/job.type.service.ts @@ -59,8 +59,8 @@ export const jobType = createApi({ }), }), // 🔹 GET: Fetch all posts - getJobType: builder.query({ - query: () => "/job-type", + getJobType: builder.query({ + query: (page = 1) => `/job-type?page=${page}`, }), updateJobType: builder.mutation({ diff --git a/src/Redux/Service/template.master.service.ts b/src/Redux/Service/template.master.service.ts index e6a3ef6..f770228 100644 --- a/src/Redux/Service/template.master.service.ts +++ b/src/Redux/Service/template.master.service.ts @@ -73,8 +73,8 @@ export const templateMaster = createApi({ }), }), // 🔹 GET: Fetch all posts - getTemplateMaster: builder.query({ - query: () => "/template-master", + getTemplateMaster: builder.query({ + query: (page = 1) => `/template-master?page=${page}`, }), updateTemplateMaster: builder.mutation({ diff --git a/src/Redux/Store.tsx b/src/Redux/Store.tsx index a97cdac..3dd366c 100644 --- a/src/Redux/Store.tsx +++ b/src/Redux/Store.tsx @@ -19,6 +19,7 @@ import { templateMaster } from "./Service/template.master.service"; import { jobType } from "./Service/job.type.service"; import { industryMaster } from "./Service/industry.master.service"; import { profile } from "./Service/profile.password"; +import { countryMaster } from "./Service/country.master"; export const store = configureStore({ reducer: { @@ -41,6 +42,7 @@ export const store = configureStore({ [jobType.reducerPath]: jobType.reducer, [industryMaster.reducerPath]: industryMaster.reducer, [profile.reducerPath]: profile.reducer, + [countryMaster.reducerPath]: countryMaster.reducer, auth: authReducer, }, middleware: (getDefaultMiddleware) => @@ -63,6 +65,7 @@ export const store = configureStore({ jobType.middleware, industryMaster.middleware, profile.middleware, + countryMaster.middleware, ), }); diff --git a/src/components/DataTable.tsx b/src/components/DataTable.tsx index a43ee43..f7e33b1 100644 --- a/src/components/DataTable.tsx +++ b/src/components/DataTable.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useState } from "react"; import { HStack, Stack, Table } from "@chakra-ui/react"; import { PaginationItems, PaginationNextTrigger, PaginationPrevTrigger, PaginationRoot } from "./ui/pagination"; // import { @@ -12,8 +12,13 @@ interface TableProps { tableHeadRow: string[]; data: Record[]; sortableColumns?: string[]; // Specify which columns are sortable - paginationData?: any, - refetch?: (params?: any) => void; + paginationData?: { + current_page: number; + last_page: number; + per_page: number; + total: number; + }, + onPageChange?: (page: number) => void; } const DataTable: React.FC = ({ @@ -21,30 +26,18 @@ const DataTable: React.FC = ({ data, sortableColumns = [], paginationData, - refetch -}) => { - const totalCount = paginationData?.total || 0; - const pageSize = paginationData?.per_page || 10; - const currentPage = paginationData?.current_page || 1; - const lastPage = paginationData?.last_page || 1; - const [page, setPage] = useState(currentPage); - - const [sortedData, setSortedData] = useState(data); + onPageChange +}: TableProps) => { + const { current_page = 1, last_page = 1 } = paginationData || {}; const [sortConfig, setSortConfig] = useState<{ key: string; direction: "asc" | "desc"; } | null>(null); - useEffect(() => { - setSortedData(data); - }, [data]); - - const handlePageChange = (newPage: any) => { - if (newPage >= 1 && newPage <= lastPage) { - setPage(newPage); - if (refetch) { - refetch({ page: newPage }); - } + const handlePageChange = (details: { page: number }) => { + const newPage = details.page; + if (newPage >= 1 && newPage <= last_page) { + onPageChange?.(newPage); } }; @@ -60,14 +53,9 @@ const DataTable: React.FC = ({ direction = "desc"; } - const sortedArray = [...sortedData].sort((a, b) => { - if (a[column] < b[column]) return direction === "asc" ? -1 : 1; - if (a[column] > b[column]) return direction === "asc" ? 1 : -1; - return 0; - }); - - setSortedData(sortedArray); - setSortConfig({ key: column, direction }); + const newSortConfig = { key: column, direction }; + setSortConfig(newSortConfig); + onPageChange?.(1); }; return ( @@ -110,7 +98,7 @@ const DataTable: React.FC = ({ - {sortedData.map((item: any, index) => ( + {data.map((item: any, index) => ( = ({ - {lastPage > 1 && 1 && ( - handlePageChange(page - 1)} disabled={page === 1} /> + handlePageChange({ page: current_page - 1 })} disabled={current_page === 1} /> - handlePageChange(page + 1)} disabled={page === lastPage} /> + handlePageChange({ page: current_page + 1 })} disabled={current_page === last_page} /> - } + )} ); }; diff --git a/src/components/ui/pagination.tsx b/src/components/ui/pagination.tsx index 92e7175..ff2fe62 100644 --- a/src/components/ui/pagination.tsx +++ b/src/components/ui/pagination.tsx @@ -198,16 +198,40 @@ export const PaginationNextTrigger = React.forwardRef< export const PaginationItems = (props: React.HTMLAttributes) => { return ( - {({ pages }) => - pages.map((page, index) => ( - - )) - } + {({ pages }) =>( + <> + {pages.map((page, index) => { + if(page.type === "ellipsis") { + return ( + ( + + ... + + ) + ) + } + if (page.type === 'page') { + return ( + + ); + } + + // Skip rendering for other types + return null; + })} + + )} ); };