-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from CMP26Projects/change-password
Change password and cancel week
- Loading branch information
Showing
10 changed files
with
183 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<form onSubmit={handleSubmit} className="cancel-week container"> | ||
<PageTitle title="إلغاء الأسبوع" /> | ||
<h4>هل أنت متأكد من إلغاء الأسبوع؟</h4> | ||
<p>إلغاء الاسبوع قرار مهم و لا يمكن التراجع عنه</p> | ||
<CustomCheckbox | ||
labels={["لقد فهمت"]} | ||
values={["understand"]} | ||
checkedValues={understandCheckbox ? ["understand"] : []} | ||
onChange={(e) => setUnderstandCheckbox(e.target.checked)} | ||
name="understand" | ||
required | ||
/> | ||
<Button | ||
className="cancel-week__btn Button--medium Button--danger" | ||
type="submit" | ||
> | ||
إلغاء الأسبوع | ||
</Button> | ||
{isLoading && <p>جاري إلغاء الأسبوع</p>} | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.cancel-week { | ||
direction: rtl; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
|
||
.Button { | ||
width: 50%; | ||
margin-inline: auto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useState } from "react"; | ||
import Button from "../common/Button"; | ||
import TextInput from "../common/Inputs"; | ||
import "./EditPassword.scss"; | ||
import PageTitle from "../common/PageTitle"; | ||
import { useChangePasswordMutation } from "../../redux/slices/usersApiSlice"; | ||
import { toast } from "react-toastify"; | ||
|
||
export default function EditPassword() { | ||
const [oldPassword, setOldPassword] = useState(""); | ||
const [newPassword, setNewPassword] = useState(""); | ||
|
||
const [changePassword, { isLoading }] = useChangePasswordMutation(); | ||
|
||
const submitHandler = async (e) => { | ||
e.preventDefault(); | ||
console.log({ oldPassword, newPassword }); | ||
|
||
try { | ||
const res = await changePassword({ oldPassword, newPassword }).unwrap(); | ||
if (res.status === 400 || res.status === 500) | ||
throw new Error("Something went wrong while changing the password"); | ||
toast.success("تم تغيير كلمة السر بنجاح"); | ||
} catch (err) { | ||
toast.error("حدث خطأ أثناء تغيير كلمة السر"); | ||
toast.error(JSON.stringify(err)); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={submitHandler} className="edit-password container"> | ||
<PageTitle title="تغيير كلمة السر" /> | ||
<TextInput | ||
label="الرمز السري القديم" | ||
type="password" | ||
name="oldPassword" | ||
value={oldPassword} | ||
placeholder="********" | ||
onChange={(e) => setOldPassword(e.target.value)} | ||
required={true} | ||
/> | ||
<TextInput | ||
label="الرمز السري الجديد" | ||
type="password" | ||
name="newPassword" | ||
value={newPassword} | ||
onChange={(e) => setNewPassword(e.target.value)} | ||
placeholder="********" | ||
required={true} | ||
/> | ||
<Button | ||
className="edit-password__btn Button--medium Button--primary-darker" | ||
type="submit" | ||
> | ||
تغيير كلمة السر | ||
</Button> | ||
{isLoading && <p>جاري تغيير كلمة السر</p>} | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.edit-password { | ||
direction: rtl; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
|
||
.Button { | ||
width: 50%; | ||
margin-inline: auto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters