update changes

This commit is contained in:
YasinShaikh123
2024-12-09 20:10:47 +05:30
parent fed5125660
commit 9c0b231e62
10 changed files with 329 additions and 343 deletions

View File

@@ -29,10 +29,8 @@ export const addSubAdmin = yup.object().shape({
.max(50, "First Name cannot exceed 50 characters")
.matches(/^[^\d]+$/, "First Name cannot contain numbers"),
lastName: yup
.string()
.required("Last Name name in arabic is required"),
emailAddress: yup.string().email("Invalid email address").notRequired(),
lastName: yup.string().required("Last Name name in arabic is required"),
emailAddress: yup.string().email("Invalid email address").notRequired(),
// .test("emailValidity", "Email address is invalid", async function (value) {
// if (!value) {
// return true; // Allow if the field is empty
@@ -95,29 +93,30 @@ const SubAdminUpdateCreate = () => {
lastName: subAdminByIdData?.data?.lastName,
emailAddress: subAdminByIdData?.data?.emailAddress,
});
setIsSwitchOn(subAdminByIdData?.data?.role[0]?.role===encryptString(import.meta.env.VITE_VITE_MAKER));
setIsSwitchOn(
subAdminByIdData?.data?.role[0]?.role ===
encryptString(import.meta.env.VITE_VITE_MAKER)
);
console.log(subAdminByIdData?.data?.role);
}
}, [subAdminByIdData, reset]);
if (false) {
return <FullscreenLoaders />;
}
// ============================ [API]===============================
const handleConfirm = async () => {
setIsLoadingBtn(true);
const id = params?.id;
console.log(isSwitchOn);
if (id) {
try {
const formData = {
...form,
role_xid: isSwitchOn?2:1,
// role_xid: !isSwitchOn ? 1 : 2,
};
await updateSubAdmin({ data: formData, id }).then((response) => {
if (response?.data?.statusCode) {
@@ -151,7 +150,7 @@ const SubAdminUpdateCreate = () => {
try {
const formData = {
...form,
role_xid: isSwitchOn?2:1,
role_xid: isSwitchOn ? 1 : 2,
};
await createSubAdmin(formData).then((response) => {
console.log(response);
@@ -282,11 +281,11 @@ const SubAdminUpdateCreate = () => {
}, {});
// ==================== [On Submit] ========================
console.log(errors);
console.log(errors);
const onSubmit = async (data) => {
console.log("Hit");
if (Object.keys(errors).length === 0) {
setForm(data);
setAlert(true);
@@ -314,10 +313,14 @@ console.log(errors);
<ArrowBackIcon fontSize={"xl"} me={2} />
Add Details
</Text>
<RoleSwitchButton
isSwitchOn={isSwitchOn}
setIsSwitchOn={setIsSwitchOn}
/>
{params?.id ? (
""
) : (
<RoleSwitchButton
isSwitchOn={isSwitchOn}
setIsSwitchOn={setIsSwitchOn}
/>
)}
</Box>
{/* ====================== [Form Input] ====================== */}