Skip to content

Commit b827b82

Browse files
authored
fixing error display in reset password (#71)
1 parent 1fcc7ec commit b827b82

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

Diff for: src/components/layout/Header.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ const Header: React.FC = () => {
9898
: 0;
9999

100100
function formatName(name: string) {
101-
const trimmedName = name.trim();
102-
const formattedName = trimmedName.replace(/\s+/g, '.');
103-
return formattedName.length > 5 ? formattedName.substring(0, 5) + '...' : formattedName;
101+
const trimmedName = name?.trim();
102+
const formattedName = trimmedName?.replace(/\s+/g, '.');
103+
return formattedName?.length > 5 ? formattedName?.substring(0, 5) + '...' : formattedName;
104104
}
105105

106106
const switch2FA = async () => {

Diff for: src/pages/ResetPassword.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const ResetPassword: React.FC = () => {
2323
const navigate = useNavigate();
2424
const location = useLocation();
2525
const dispatch = useAppDispatch();
26-
const { user, isError, isSuccess, isLoading, message } = useAppSelector(
26+
const { user, fail, isSuccess, isLoading, message } = useAppSelector(
2727
(state) => state?.auth
2828
);
2929
const [isFormVisible, setIsFormVisible] = useState(true);
@@ -46,14 +46,14 @@ const ResetPassword: React.FC = () => {
4646
},
4747
});
4848
useEffect(() => {
49-
if (isError) {
49+
if (fail) {
5050
formik.setStatus(message);
5151
}
5252
if (isSuccess) {
5353
toast.success(message);
5454
setIsFormVisible(false);
5555
}
56-
}, [user, isError, isSuccess, isLoading, message]);
56+
}, [user, fail, isSuccess, isLoading, message]);
5757

5858
useEffect(() => {
5959
dispatch(resetAuth());
@@ -115,7 +115,7 @@ const ResetPassword: React.FC = () => {
115115
</button>
116116
</div>
117117
<div>
118-
{showError || isError ? (
118+
{showError || fail ? (
119119
<p className="error">{formik.status}</p>
120120
) : null}
121121
</div>

Diff for: src/pages/SendResetPasswordLink.tsx

+7-11
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,29 @@ const ResetPasswordSchema = Yup.object().shape({
1616
const SendResetPasswordLink: React.FC = () => {
1717
const [hideParagraph, setHideParagraph] = useState(true);
1818
const dispatch = useAppDispatch();
19-
const { user, isError, isSuccess, isLoading, message } = useAppSelector(
19+
const { user, fail, isSuccess, isLoading, message } = useAppSelector(
2020
(state) => state?.auth
2121
);
2222
const formik = useFormik({
2323
initialValues: {
2424
email: "",
2525
},
2626
validationSchema: ResetPasswordSchema,
27-
onSubmit: (values, { setStatus }) => {
28-
dispatch(sendResetLink(values.email)).then(() => {
29-
if (isError) {
30-
setStatus(message);
31-
}
32-
});
33-
},
27+
onSubmit: (values) => {
28+
dispatch(sendResetLink(values.email))
29+
}
3430
});
3531

3632
useEffect(() => {
37-
if (isError) {
33+
if (fail) {
3834
formik.setStatus(message);
3935
}
4036
if (isSuccess) {
4137
toast.success(message);
4238
formik.resetForm();
4339
setHideParagraph(false);
4440
}
45-
}, [isError, isSuccess, message]);
41+
}, [fail, isSuccess, message]);
4642
useEffect(() => {
4743
dispatch(resetAuth());
4844
}, [dispatch]);
@@ -73,7 +69,7 @@ const SendResetPasswordLink: React.FC = () => {
7369
Email Address
7470
</label>
7571
</div>
76-
{isError && <p className="error">{formik.status}</p>}
72+
{fail? (<p className="error">{formik.status}</p>):null}
7773
<br />
7874
<button
7975
className={`reset-Button${isLoading ? " loading" : ""}`}

Diff for: src/store/features/auth/authSlice.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const initialState: AuthService = {
1717
isAuthenticated: false,
1818
error: "",
1919
userId: "",
20+
fail: false
2021
};
2122

2223
type IUserEmailAndPassword = Pick<IUser, 'email' | 'password'>;
@@ -185,6 +186,7 @@ const userSlice = createSlice({
185186
state.token = "";
186187
state.isAuthenticated = false;
187188
state.error = "";
189+
state.fail= false;
188190
},
189191
changingProfile: (state, action: any)=>{
190192
(state.user as any).profilePicture = action.payload
@@ -279,7 +281,7 @@ const userSlice = createSlice({
279281
)
280282
.addCase(sendResetLink.pending, (state) => {
281283
state.isLoading = true;
282-
state.isError = false;
284+
state.fail = false;
283285
state.isSuccess = false;
284286
})
285287
.addCase(sendResetLink.fulfilled, (state, action: PayloadAction<any>) => {
@@ -290,24 +292,23 @@ const userSlice = createSlice({
290292
.addCase(sendResetLink.rejected, (state, action: PayloadAction<any>) => {
291293
state.isLoading = false;
292294
state.isSuccess = false;
293-
state.isError = true;
295+
state.fail = true;
294296
state.message = action.payload;
295297
})
296298
.addCase(resetPassword.pending, (state) => {
297299
state.isLoading = true;
298-
state.isError = false;
300+
state.fail = false;
299301
state.isSuccess = false;
300302
})
301303
.addCase(resetPassword.fulfilled, (state, action: PayloadAction<any>) => {
302304
state.isLoading = false;
303305
state.isSuccess = true;
304-
state.user = action.payload;
305306
state.message = action.payload.message;
306307
})
307308
.addCase(resetPassword.rejected, (state, action: PayloadAction<any>) => {
308309
state.isLoading = false;
309310
state.isSuccess = false;
310-
state.isError = true;
311+
state.fail = true;
311312
state.message = action.payload;
312313
})
313314
.addCase(loginUser.pending, (state) => {

Diff for: src/utils/types/store.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface AuthService {
7777
error: string;
7878
token: string;
7979
userId?: any;
80+
fail:boolean;
8081
}
8182

8283
export interface IEmail {

0 commit comments

Comments
 (0)