Merge branch 'dev' of http://git.wdipl.com/Siddhesh.More/tanami-admin-panel into dev
This commit is contained in:
@@ -95,11 +95,16 @@ const IODetails = ({ enableNextTab, index }) => {
|
||||
useContext(GlobalStateContext);
|
||||
|
||||
// ======================[ RTK Querry Api ]
|
||||
|
||||
|
||||
const {
|
||||
data: investmentTypeData,
|
||||
isLoading: investmentTypeIsLoading,
|
||||
error: investmentTypeError,
|
||||
} = useGetInvestmentTypesQuery();
|
||||
data: investmentTypes,
|
||||
isLoading: investmentTypesLoading,
|
||||
error,
|
||||
} = useGetInvestmentTypesQuery({ page: 1, size: 10 })
|
||||
|
||||
|
||||
|
||||
const {
|
||||
data: activeSponsers,
|
||||
isLoading: activeSponsersIsLoading,
|
||||
@@ -114,7 +119,7 @@ const IODetails = ({ enableNextTab, index }) => {
|
||||
const [updateIO] = useUpdateIOMutation();
|
||||
|
||||
// ======================[ Selector filter ]
|
||||
const investmentTypeOptions = investmentTypeData?.data?.rows?.map(
|
||||
const investmentTypeOptions = investmentTypes?.data?.rows?.map(
|
||||
({ investmentTypeName, id }) => {
|
||||
return {
|
||||
label: investmentTypeName,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import { OPACITY_ON_LOAD } from "../../../Layout/animations";
|
||||
import { Box } from "@chakra-ui/react";
|
||||
import { Box, useToast } from "@chakra-ui/react";
|
||||
import { useForm, Controller } from "react-hook-form";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import * as yup from "yup";
|
||||
@@ -22,12 +22,10 @@ import FullscreenLoaders from "../../../Components/Loaders/FullscreenLoaders";
|
||||
export const addSponser = yup.object().shape({
|
||||
sponsorName: yup.string().required("Sponser name is required"),
|
||||
sponsorNameArabic: yup.string().required("Sponser name is required"),
|
||||
mobileNo: yup
|
||||
email: yup
|
||||
.string()
|
||||
.required("Mobile no is required")
|
||||
.matches(/^[0-9]+$/, "Mobile no must be only digits")
|
||||
.min(10, "Mobile no must be at least 10 digits")
|
||||
.max(10, "Mobile no must be at most 15 digits"),
|
||||
.email("Must be a valid email")
|
||||
.required("Email is required"),
|
||||
});
|
||||
|
||||
export function debounce(func, delay) {
|
||||
@@ -39,9 +37,10 @@ export function debounce(func, delay) {
|
||||
}
|
||||
|
||||
const AddSponser = () => {
|
||||
const toast = useToast();
|
||||
const params = useParams();
|
||||
const id = params?.id
|
||||
const navigate = useNavigate();
|
||||
const [isLoadingBtn, setIsLoadingBtn] = useState(false);
|
||||
const [bannerImageData, setBannerImageData] = useState(null);
|
||||
const [selectedBannerImageData, setSelectedBannerImageData] = useState(null);
|
||||
|
||||
@@ -51,8 +50,19 @@ const AddSponser = () => {
|
||||
const [createSponser] = useCreateSponserMutation();
|
||||
const [updateSponser] = useUpdateSponserMutation();
|
||||
|
||||
const id = params?.id;
|
||||
console.log(id);
|
||||
|
||||
const { data, error, isLoading } = useGetSponserByIdQuery(id, { skip: !id });
|
||||
// Fetch sponsor data only if id exists
|
||||
const {
|
||||
data: sponserByIdData,
|
||||
error,
|
||||
isLoading,
|
||||
} = useGetSponserByIdQuery(id, {
|
||||
skip: !id,
|
||||
});
|
||||
|
||||
console.log(sponserByIdData?.data);
|
||||
|
||||
const {
|
||||
control,
|
||||
@@ -63,22 +73,19 @@ const AddSponser = () => {
|
||||
resolver: yupResolver(addSponser),
|
||||
});
|
||||
|
||||
console.log(errors);
|
||||
useEffect(() => {
|
||||
if (sponserByIdData?.data) {
|
||||
reset({
|
||||
sponsorName: sponserByIdData?.data?.sponsorName,
|
||||
sponsorNameArabic: sponserByIdData?.data?.sponsorNameArabic,
|
||||
email: sponserByIdData?.data?.email,
|
||||
});
|
||||
}
|
||||
}, [sponserByIdData, reset]);
|
||||
|
||||
// useEffect(() => {
|
||||
// if (data) {
|
||||
// reset({
|
||||
// sponsorName: data?.data?.sponsorName,
|
||||
// mobileNo: data?.data?.mobileNo,
|
||||
// sponsorNameArabic: data?.data?.sponsorNameArabic,
|
||||
// });
|
||||
// }
|
||||
// }, [data, reset]);
|
||||
|
||||
if (isLoading) {
|
||||
if (false) {
|
||||
return <FullscreenLoaders />;
|
||||
}
|
||||
|
||||
|
||||
const formFields = [
|
||||
{
|
||||
@@ -96,13 +103,13 @@ const AddSponser = () => {
|
||||
type: "text",
|
||||
isRequired: true,
|
||||
section: "Add Details",
|
||||
isArabic:true
|
||||
isArabic: true,
|
||||
},
|
||||
{
|
||||
label: "Mobile Number",
|
||||
name: "mobileNo",
|
||||
label: "Email address",
|
||||
name: "email",
|
||||
placeHolder: " ",
|
||||
type: "number",
|
||||
type: "email",
|
||||
isRequired: true,
|
||||
section: "Add Details",
|
||||
},
|
||||
@@ -124,13 +131,13 @@ const AddSponser = () => {
|
||||
type: "text",
|
||||
isRequired: true,
|
||||
section: "Add Details",
|
||||
isArabic:true
|
||||
isArabic: true,
|
||||
},
|
||||
{
|
||||
label: "Mobile Number",
|
||||
name: "mobileNo",
|
||||
label: "Email adress",
|
||||
name: "email",
|
||||
placeHolder: " ",
|
||||
type: "number",
|
||||
type: "email",
|
||||
isRequired: true,
|
||||
section: "Add Details",
|
||||
},
|
||||
@@ -155,34 +162,62 @@ const AddSponser = () => {
|
||||
}, {});
|
||||
|
||||
const onSubmit = async (data) => {
|
||||
setIsLoadingBtn(true);
|
||||
console.log(data);
|
||||
// setSponser([
|
||||
// {
|
||||
// ...data,
|
||||
// status: true,
|
||||
// id: uuidv4(),
|
||||
// createdAt: new Date().toISOString(),
|
||||
// },
|
||||
// ...sponser,
|
||||
// ]);
|
||||
navigate("/sponser");
|
||||
const id = params?.id
|
||||
try {
|
||||
await createSponser(data).then((response) => {
|
||||
if (response?.data?.statusCode) {
|
||||
toast({
|
||||
render: () => <ToastBox message={response?.data?.message} />,
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
render: () => (
|
||||
<ToastBox message={"Something Went Wrong"} status={"error"} />
|
||||
),
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
const id = params?.id;
|
||||
if (id) {
|
||||
try {
|
||||
await updateSponser({ data, id }).then((response) => {
|
||||
if (response?.data?.statusCode) {
|
||||
toast({
|
||||
render: () => <ToastBox message={response?.data?.message} />,
|
||||
});
|
||||
|
||||
setIsLoadingBtn(false);
|
||||
navigate("/sponser");
|
||||
} else {
|
||||
toast({
|
||||
render: () => (
|
||||
<ToastBox message={"Something Went Wrong"} status={"error"} />
|
||||
),
|
||||
});
|
||||
|
||||
setIsLoadingBtn(false);
|
||||
navigate("/sponser");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
setIsLoadingBtn(false);
|
||||
navigate("/sponser");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
await createSponser(data).then((response) => {
|
||||
if (response?.data?.statusCode) {
|
||||
toast({
|
||||
render: () => <ToastBox message={response?.data?.message} />,
|
||||
});
|
||||
|
||||
setIsLoadingBtn(false);
|
||||
navigate("/sponser");
|
||||
} else {
|
||||
toast({
|
||||
render: () => (
|
||||
<ToastBox message={"Something Went Wrong"} status={"error"} />
|
||||
),
|
||||
});
|
||||
|
||||
setIsLoadingBtn(false);
|
||||
navigate("/sponser");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
setIsLoadingBtn(false);
|
||||
navigate("/sponser");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -193,6 +228,8 @@ const AddSponser = () => {
|
||||
control={control}
|
||||
errors={errors}
|
||||
onSubmit={handleSubmit(onSubmit)}
|
||||
submitTitle={params?.id ? "Update" : "Submit"}
|
||||
btnLoading={isLoadingBtn}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
Button,
|
||||
HStack,
|
||||
@@ -84,8 +85,8 @@ const Sponser = () => {
|
||||
// ====================================================[Table Setup]================================================================
|
||||
const tableHeadRow = [
|
||||
"Sponsor name",
|
||||
"Sponsor name (Arabic)",
|
||||
"Mobile no",
|
||||
// "Sponsor name (Arabic)",
|
||||
"Email address",
|
||||
"Status",
|
||||
"Created At",
|
||||
"Action",
|
||||
@@ -158,30 +159,33 @@ const Sponser = () => {
|
||||
</Text>
|
||||
),
|
||||
|
||||
"Sponsor name (Arabic)":(<Text
|
||||
justifyContent={slideFromRight ? "right" : "left"}
|
||||
as={"span"}
|
||||
color={"teal.900"}
|
||||
fontWeight={"500"}
|
||||
className="d-flex align-items-center web-text-small"
|
||||
>
|
||||
{item.sponsorNameArabic}
|
||||
</Text>),
|
||||
"Mobile no": (
|
||||
// "Sponsor name (Arabic)":(<Text
|
||||
// justifyContent={slideFromRight ? "right" : "left"}
|
||||
// as={"span"}
|
||||
// color={"teal.900"}
|
||||
// fontWeight={"500"}
|
||||
// className="d-flex align-items-center web-text-small"
|
||||
// >
|
||||
// {item.sponsorNameArabic}
|
||||
// </Text>),
|
||||
"Email address": (
|
||||
<Box w={"auto"} isTruncated={true}>
|
||||
<Text as={"span"} color={"teal.900"} fontWeight={"500"}>
|
||||
{item.mobileNo}
|
||||
{item.email}
|
||||
</Text>
|
||||
</Box>
|
||||
),
|
||||
Status: (
|
||||
<Box minW={24} isTruncated={true}>
|
||||
<Switch
|
||||
{/* <Switch
|
||||
size={"sm"}
|
||||
colorScheme="green"
|
||||
onChange={() => handleUpdateStatus(item.id)}
|
||||
isChecked={item.isActive}
|
||||
/>
|
||||
/> */}
|
||||
<Badge fontWeight={'500'} textTransform={'none'} color={item.isActive ? "green" : "red"} px={2} py={0.5}>
|
||||
{item.isActive ? "Active":"Inactive"}
|
||||
</Badge>
|
||||
</Box>
|
||||
),
|
||||
|
||||
@@ -236,7 +240,7 @@ const Sponser = () => {
|
||||
placement="top"
|
||||
>
|
||||
<Button
|
||||
onClick={() => navigate(`/sponser/${item.id}`)}
|
||||
onClick={() => navigate(`/sponser/add-sponser/${item.id}`)}
|
||||
_hover={{ color: "blue.500" }}
|
||||
// transition={"0.5s all"}
|
||||
color="blue.400"
|
||||
|
||||
@@ -42,7 +42,8 @@ export const RouteLink = [
|
||||
// ===============[ Management]===============
|
||||
{ path: "/", Component: Sponser },
|
||||
{ path: "/sponser", Component: Sponser },
|
||||
{ path: "/sponser/:id", Component: AddSponser },
|
||||
{ path: "/sponser/add-sponser/:id", Component: AddSponser },
|
||||
{ path: "/sponser/add-sponser", Component: AddSponser },
|
||||
{ path: "/sponser/view-sponser/:id", Component: ViewSponser },
|
||||
{ path: "/sponser/edit-sponser/:id", Component: EditSponser },
|
||||
|
||||
@@ -52,6 +53,12 @@ export const RouteLink = [
|
||||
{ path: "/exchange-rate", Component: ExchangeRate },
|
||||
{ path: "/investment-type", Component: InvestmentType },
|
||||
{ path: "/investment-type/add-investment", Component: AddInvestmentType },
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{ path: "/investment-type/view-investment/:id", Component: ViewInvestmentType },
|
||||
{ path: "/investment-type/edit-investment/:id", Component: EditInvestmentType },
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ export const ioService = createApi({
|
||||
query: ({ page, size }) => `/io/admin?page=${page}&size=${size}`,
|
||||
providesTags: ["getIO"],
|
||||
}),
|
||||
|
||||
|
||||
|
||||
getIOById: builder.query({
|
||||
query: (id) => ({ url: `/io/admin/${id}` }),
|
||||
providesTags: ["getIO"],
|
||||
|
||||
@@ -30,13 +30,31 @@ export const sponserMaster = createApi({
|
||||
|
||||
getSponserMasterActive: builder.query({
|
||||
query: () => "/sponsor/admin/active",
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
,
|
||||
|
||||
|
||||
|
||||
getSponserById: builder.query({
|
||||
query: (id) => ({ url: `/sponsor/admin/${id}` }),
|
||||
query: (id) => `/sponsor/admin/${id}`,
|
||||
providesTags: ["getSponser"],
|
||||
}),
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
toggleStatus: builder.mutation({
|
||||
query: ({ id }) => ({
|
||||
url: `/sponsor/admin/toggle-status/${id}`,
|
||||
|
||||
Reference in New Issue
Block a user