diff --git a/client/src/components/cancel-week/CancelWeek.jsx b/client/src/components/cancel-week/CancelWeek.jsx new file mode 100644 index 00000000..fed75bf3 --- /dev/null +++ b/client/src/components/cancel-week/CancelWeek.jsx @@ -0,0 +1,54 @@ +import { useState } from "react"; +import PageTitle from "../common/PageTitle"; +import CustomCheckbox from "../common/CustomCheckbox"; +import Button from "../common/Button"; +import "./CancelWeek.scss"; +import { useCancelWeekMutation } from "../../redux/slices/termApiSlice"; +import { toast } from "react-toastify"; +import { useNavigate } from "react-router-dom"; + +export default function CancelWeek() { + const [understandCheckbox, setUnderstandCheckbox] = useState(false); + + const [cancelWeek, { isLoading }] = useCancelWeekMutation(); + const navigate = useNavigate(); + + const handleSubmit = async (e) => { + e.preventDefault(); + + try { + const res = await cancelWeek().unwrap(); + if (res.status === 400 || res.status === 500) + throw new Error("Something went wrong while canceling the week"); + toast.success("تم إلغاء الأسبوع بنجاح"); + navigate("/dashboard"); + } catch (err) { + console.log(err); + toast.error("حدث خطأ أثناء إلغاء الأسبوع"); + toast.error(JSON.stringify(err)); + } + }; + + return ( +
+ +

هل أنت متأكد من إلغاء الأسبوع؟

+

إلغاء الاسبوع قرار مهم و لا يمكن التراجع عنه

+ setUnderstandCheckbox(e.target.checked)} + name="understand" + required + /> + + {isLoading &&

جاري إلغاء الأسبوع

} + + ); +} diff --git a/client/src/components/cancel-week/CancelWeek.scss b/client/src/components/cancel-week/CancelWeek.scss new file mode 100644 index 00000000..bdb0bb9e --- /dev/null +++ b/client/src/components/cancel-week/CancelWeek.scss @@ -0,0 +1,11 @@ +.cancel-week { + direction: rtl; + display: flex; + flex-direction: column; + gap: 1rem; + + .Button { + width: 50%; + margin-inline: auto; + } +} diff --git a/client/src/components/captain-profile/CaptainProfile.jsx b/client/src/components/captain-profile/CaptainProfile.jsx index 8cbf4309..8d301f23 100644 --- a/client/src/components/captain-profile/CaptainProfile.jsx +++ b/client/src/components/captain-profile/CaptainProfile.jsx @@ -41,11 +41,14 @@ export default function CaptainProfile() { {userInfo.rSectorBaseName ? userInfo.rSectorBaseName + " " + userInfo.rSectorSuffixName : "لا يوجد"} + {(userInfo.type === "unit" || userInfo.type == "general") && ""}

- {/* TODO: Add the route for The Button Later */} - diff --git a/client/src/components/common/InfoSection.jsx b/client/src/components/common/InfoSection.jsx index ca11a296..c434d51c 100644 --- a/client/src/components/common/InfoSection.jsx +++ b/client/src/components/common/InfoSection.jsx @@ -46,7 +46,7 @@ export default function InfoSection() { ? "جاري التحميل" : !absenceRate ? "لا يوجد بيانات" - : Math.reound(absenceRate?.body * 100) + "%" + : Math.round(absenceRate?.body * 100) + "%" } color="dark" /> diff --git a/client/src/components/common/TermInfoSection.jsx b/client/src/components/common/TermInfoSection.jsx index bf2f926b..ebac1a87 100644 --- a/client/src/components/common/TermInfoSection.jsx +++ b/client/src/components/common/TermInfoSection.jsx @@ -16,15 +16,15 @@ export default function TermInfoSection() { isLoading, } = useGetRemainingWeeksQuery(); - if ( - termInfo && - !isFetchingTerm && - curWeek && - !isFetchingWeek && - weeksLeft && - !isFetchingWeeksLeft - ) - console.log({ termInfo, curWeek, weeksLeft }); + // if ( + // termInfo && + // !isFetchingTerm && + // curWeek && + // !isFetchingWeek && + // weeksLeft && + // !isFetchingWeeksLeft + // ) + // console.log({ termInfo, curWeek, weeksLeft }); return (
- + {isLoading &&

جاري تغيير كلمة السر

} + + ); +} diff --git a/client/src/components/edit-password/EditPassword.scss b/client/src/components/edit-password/EditPassword.scss new file mode 100644 index 00000000..8ae2bb00 --- /dev/null +++ b/client/src/components/edit-password/EditPassword.scss @@ -0,0 +1,11 @@ +.edit-password { + direction: rtl; + display: flex; + flex-direction: column; + gap: 1rem; + + .Button { + width: 50%; + margin-inline: auto; + } +} diff --git a/client/src/redux/slices/termApiSlice.js b/client/src/redux/slices/termApiSlice.js index 205a22d9..6a241c13 100644 --- a/client/src/redux/slices/termApiSlice.js +++ b/client/src/redux/slices/termApiSlice.js @@ -48,6 +48,13 @@ export const termApi = apiSlice.injectEndpoints({ }), invalidatesTags: ["Term", "Weeks"], }), + CancelWeek: builder.mutation({ + query: () => ({ + url: `${TERM_URL}/week`, + method: "PATCH", + }), + invalidatesTags: ["Weeks"], + }), }), }); @@ -58,4 +65,5 @@ export const { useGetRemainingWeeksQuery, useInsertTermMutation, useUpdateTermMutation, + useCancelWeekMutation, } = termApi; diff --git a/client/src/redux/slices/usersApiSlice.js b/client/src/redux/slices/usersApiSlice.js index 3d1fb386..839180d8 100644 --- a/client/src/redux/slices/usersApiSlice.js +++ b/client/src/redux/slices/usersApiSlice.js @@ -26,8 +26,19 @@ export const usersApi = apiSlice.injectEndpoints({ }), invalidatesTags: ["Captains", "auth"], }), + changePassword: builder.mutation({ + query: (data) => ({ + url: `${USERS_API}/newPassword`, + method: "POST", + body: data, + }), + }), }), }); -export const { useLoginMutation, useLogoutMutation, useSignupMutation } = - usersApi; +export const { + useLoginMutation, + useLogoutMutation, + useSignupMutation, + useChangePasswordMutation, +} = usersApi; diff --git a/client/src/routes.jsx b/client/src/routes.jsx index f4d836f4..8fd21a4c 100644 --- a/client/src/routes.jsx +++ b/client/src/routes.jsx @@ -30,6 +30,8 @@ import NotificationsPage from "./components/notifications/notificationPage"; import ScoutsAttendance from "./components/scouts-attendance/ScoutsAttendance"; import MoneyPage from "./components/moneypage/MoneyPage"; import CaptainsAttendance from "./components/captains-attendance/CaptainAttendance"; +import EditPassword from "./components/edit-password/EditPassword"; +import CancelWeek from "./components/cancel-week/CancelWeek"; import ActivityPage from "./components/activitypage/ActivityPage"; import AddActivityPage from "./components/addactivitypage/AddActivityPage"; @@ -49,7 +51,12 @@ function Routes() { } /> } /> } /> - } /> + } /> + } + /> } /> } /> } /> + } /> } /> } />