Skip to content

Commit

Permalink
Update login
Browse files Browse the repository at this point in the history
  • Loading branch information
HoaAyWK committed Nov 11, 2022
1 parent 759a17a commit 00e93b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/features/account/AccountForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const AccountForm = (props) => {
const UserSchema = Yup.object().shape({
id: Yup.string(),
name: Yup.string().required('Name is required'),
email: Yup.string().required('Email is reuquired'),
email: Yup.string(),
phone: Yup.string().required('Phone is required'),
gender: Yup.mixed().oneOf(['Male', 'Female']),
address: Yup.string().required('Address is required'),
Expand Down Expand Up @@ -115,7 +115,7 @@ const AccountForm = (props) => {
<PaperStyle>
<BoxFieldStyle>
<RHFTextField name='name' label='Name *' />
<RHFTextField name='email' label='Email *' />
<RHFTextField name='email' label='Email *' disabled={true} />
<RHFTextField name='phone' label='Phone *' />
<RHFTextField name='address' label='Address *' />
<RHFTextField name='city' label='City *' />
Expand Down
13 changes: 4 additions & 9 deletions src/features/auth/authSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const login = createAsyncThunk(
const { user } = response.data;

if (!user.roles.includes(ROLES.ADMIN)) {
throw new Error('You do not have perrsion to access this page');
throw new Error('You do not have permission to access this page');
}

return response.data.user;
Expand All @@ -51,7 +51,8 @@ export const updateAccount = createAsyncThunk(
'auth/updateAccount',
async (updateBody, thunkApi) => {
try {
const { data } = await axios.put(`${BASE_API_URL}/profile`, updateBody, { withCredentials: true});
const { email, ...dataToUpdate } = updateBody;
const { data } = await axios.put(`${BASE_API_URL}/profile`, dataToUpdate, { withCredentials: true});

return data;
} catch (error) {
Expand Down Expand Up @@ -104,13 +105,7 @@ const authSlice = createSlice({
state.changedPasswordStatus = action_status.IDLE;
},
logout: (state, action) => {
state.user = null;
state.isAuthenticated = false;
state.status = action_status.IDLE;
state.updated = false;
state.changedPassword = false;
state.updateStatus = action_status.IDLE;
state.changedPasswordStatus = action_status.IDLE;
state = initialState;
localStorage.setItem('user', null);
}
},
Expand Down

0 comments on commit 00e93b4

Please sign in to comment.