181 lines
5.0 KiB
TypeScript
181 lines
5.0 KiB
TypeScript
import {
|
|
Box,
|
|
HStack,
|
|
Image,
|
|
// Image,
|
|
Input,
|
|
Text,
|
|
} from "@chakra-ui/react";
|
|
import { LuSearch } from "react-icons/lu";
|
|
// import { RiDeleteBin5Line } from "react-icons/ri";
|
|
// import AlertDailog from "../../components/AlertDailog";
|
|
import DataTable from "../../components/DataTable";
|
|
import MainFrame from "../../components/MainFrame";
|
|
import { InputGroup } from "../../components/ui/input-group";
|
|
import ManageJobsAdd from "./ManageJobsAdd";
|
|
import ViewManageJob from "./ViewManageJob";
|
|
import {
|
|
useDeleteJobsPostMutation,
|
|
useGetManageJobsQuery,
|
|
} from "../../Redux/Service/manage.jobs.service";
|
|
import { useEffect, useState } from "react";
|
|
import { Spinner } from "../../components/Sipnner/Spinner";
|
|
import Delete from "../../components/ActionIcons/Delete";
|
|
import { toaster } from "../../components/ui/toaster";
|
|
import AlertDailog from "../../components/AlertDailog";
|
|
// import { useState } from "react";
|
|
// import { useGetManageJobsQuery } from "../../Redux/Service/manage.jobs.service";
|
|
// import Delete from "../../components/ActionIcons/Delete";
|
|
|
|
// table data
|
|
|
|
const tableHeadRow = [
|
|
"Sr. No",
|
|
"Job Title",
|
|
"Workspace mode",
|
|
"Category",
|
|
"Sub-category",
|
|
"Salary",
|
|
"Action",
|
|
];
|
|
|
|
const ManageJobs = () => {
|
|
const [currentPage] = useState(1);
|
|
const [localData, setLocalData] = useState([]);
|
|
const { data, refetch, isLoading } = useGetManageJobsQuery(currentPage);
|
|
const [deleteJobsPost] = useDeleteJobsPostMutation();
|
|
const [deleteModal, setDeleteModal] = useState(false);
|
|
const [selectedJobsId, setSelectedJobsId] = useState<number | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (data) {
|
|
setLocalData((data as any)?.data?.data || []);
|
|
}
|
|
}, [data]);
|
|
console.log(data?.data.data);
|
|
|
|
const handleDeleteJobs = async (jobsId: number) => {
|
|
try {
|
|
const response = await deleteJobsPost({ id: jobsId }).unwrap();
|
|
if (response?.status === "success") {
|
|
toaster.create({
|
|
title: "Success",
|
|
description: "Jobs deleted successfully",
|
|
type: "Success",
|
|
});
|
|
refetch();
|
|
}
|
|
} catch (error) {
|
|
console.error("Error deleting FAQ:", error);
|
|
toaster.create({
|
|
title: "Error",
|
|
description: "Something went wrong",
|
|
type: "error",
|
|
});
|
|
}
|
|
};
|
|
|
|
const managepost = localData?.map((agency: any, index: number) => ({
|
|
"Sr. No": index + 1,
|
|
"Job Title": agency?.job_title,
|
|
"Workspace mode": agency?.workspace?.en_name,
|
|
Category: agency?.industry?.en_name,
|
|
"Sub-category": agency?.department?.en_name,
|
|
Salary: agency?.ctc_amount,
|
|
Action: (
|
|
<HStack justifyContent="center">
|
|
<ViewManageJob />
|
|
<ManageJobsAdd />
|
|
<AlertDailog
|
|
isOpen={deleteModal}
|
|
AltertTiggerIcon={() => (
|
|
<Delete
|
|
onClick={() => {
|
|
setSelectedJobsId(agency.id);
|
|
setDeleteModal(true);
|
|
}}
|
|
/>
|
|
)}
|
|
alertText="Delete FAQ"
|
|
alertIcon={<Image src={"DeleteIcon"} h={"39px"} />}
|
|
alertCaption="are you sure you want to delete ?"
|
|
onClose={() => setDeleteModal(false)}
|
|
onConfirm={() => {
|
|
// console.log("Deleting FAQ with ID:", selectedFaqId); // Correct ID
|
|
if (selectedJobsId) {
|
|
setDeleteModal(false);
|
|
handleDeleteJobs(selectedJobsId);
|
|
}
|
|
}}
|
|
/>
|
|
</HStack>
|
|
),
|
|
}));
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<MainFrame>
|
|
<Box
|
|
display="flex"
|
|
justifyContent="center"
|
|
alignItems="center"
|
|
height="100%"
|
|
>
|
|
<Spinner />
|
|
</Box>
|
|
</MainFrame>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<MainFrame>
|
|
<Box>
|
|
<HStack
|
|
w={"100%"}
|
|
justifyContent={"space-between"}
|
|
mb={4}
|
|
py={0}
|
|
px={3}
|
|
>
|
|
<Text as={"span"} fontSize={"sm"} fontWeight={500} color={"#000"}>
|
|
View job Posting
|
|
</Text>
|
|
|
|
<HStack>
|
|
<InputGroup
|
|
startElement={
|
|
<LuSearch
|
|
fontSize={"xs"}
|
|
style={{ position: "relative", left: "10px" }}
|
|
/>
|
|
}
|
|
color={"#000"}
|
|
>
|
|
<Input
|
|
p={3}
|
|
w={300}
|
|
bg={"#fff"}
|
|
colorPalette={"blue"}
|
|
_focus={{ border: "1px solid #02A0A0" }}
|
|
rounded={"md"}
|
|
size={"xs"}
|
|
fontSize={"sm"}
|
|
placeholder="Search..."
|
|
bgColor={"#EEEEEE"}
|
|
ps={8}
|
|
/>
|
|
</InputGroup>
|
|
{/* <Button bgColor={'#EEEEEE'} pl={3} pr={3}><IoMdAdd /> <Text>Add</Text></Button> */}
|
|
</HStack>
|
|
</HStack>
|
|
<DataTable
|
|
sortableColumns={["Name", "Registration Date "]}
|
|
tableHeadRow={tableHeadRow}
|
|
data={managepost}
|
|
/>
|
|
</Box>
|
|
</MainFrame>
|
|
);
|
|
};
|
|
export default ManageJobs;
|