Skip to content

Commit

Permalink
feat:UserMDone
Browse files Browse the repository at this point in the history
  • Loading branch information
moshdev2213 committed Oct 6, 2024
1 parent a3a3a4e commit b5583a0
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/Context/AuthContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function AuthProvider({ children }) {
};

return (
<AuthContext.Provider value={{ auth, user, role, isAuthenticated, hasRole, login, logout }}>
<AuthContext.Provider value={{ auth, user, role, isAuthenticated, hasRole, login, logout,updateUser }}>
{children}
</AuthContext.Provider>
);
Expand Down
14 changes: 9 additions & 5 deletions src/Pages/AppStack/AdminStack/Customers/Customers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import CusSwal from '../../../../Utils/Swal/CusSwal'
import PdfGenerator from '../../../../Utils/Pdfs/PdfGenerator'
import userHeader from '../../../../Utils/Pdfs/UserMHeader'
import Toaster from '../../../../Utils/Toaster/Toaster'
import LocalStore from '../../../../Store/LocalStore'

export default function Customers() {
const myId = LocalStore.getUser().Id
const navigation = useNavigate()
const [loading, setLoading] = useState(false)
const [users, setUsers] = useState([])
Expand Down Expand Up @@ -73,11 +75,13 @@ export default function Customers() {
};
// Filter users based on the search term
const filteredUsers = users.filter(user =>
user.firstName.toLowerCase().includes(searchTerm.toLowerCase()) ||
user.email.toLowerCase().includes(searchTerm.toLowerCase()) ||
user.telephone.includes(searchTerm.toLowerCase()) ||
user.status.toLowerCase().includes(searchTerm.toLowerCase()) ||
user.role.toLowerCase().includes(searchTerm.toLowerCase())
user.id !== myId && ( // Exclude the current user
user.firstName.toLowerCase().includes(searchTerm.toLowerCase()) ||
user.email.toLowerCase().includes(searchTerm.toLowerCase()) ||
user.telephone.includes(searchTerm.toLowerCase()) ||
user.status.toLowerCase().includes(searchTerm.toLowerCase()) ||
user.role.toLowerCase().includes(searchTerm.toLowerCase())
)
);

useEffect(() => {
Expand Down
81 changes: 81 additions & 0 deletions src/Pages/AppStack/AdminStack/Profile/ChangePwdProfile.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { useFormik } from 'formik';
import React from 'react'
import MyProfileYup from '../../../../Validation/MyProfile/MyProfileYup';
import Toaster from '../../../../Utils/Toaster/Toaster';
import MyProfileService from '../../../../Services/MyProfile/MyProfileService';

export default function ChangePwdProfile({ userId , loading, userValues, fetchEmployeeDetails, setLoading }) {
const { setValues, values, handleChange, handleSubmit, errors, touched } = useFormik({
initialValues: {
NewPassword: '',
ConfirmPassword: '',
},
validationSchema: MyProfileYup.changePassword,
onSubmit: async (values) => {
setLoading(true);
Toaster.loadingToast('Updating Password...');
try {
const result = await MyProfileService.changePasswordWithoutCheck(userId, values);
if (result.data.Code === 200) {
Toaster.justToast('success', result.data.Message, () => {
// navigate('/app/admin/customers');
});
}
} catch (error) {
console.error(error);
if (!error.response.data.Status) {
Toaster.justToast('error', error.response.data.Data.error, () => {

});
}
// Handle error response
} finally {
setLoading(false);
Toaster.dismissLoadingToast();
console.log('values:', values);
}
}
})
return (
<>
<div className="col-12 mb-5">
<div className="card p-4">
<h3 className='h5'>Change Password</h3>
<form className='needs-validation' noValidate onSubmit={handleSubmit}>
<div className="row row-gap-4">
<div className="col-md-12">
<input
type="password"
className={`form-control ${errors.NewPassword && touched.NewPassword ? 'is-invalid' : ''}`}
placeholder="Enter New Password"
name="NewPassword"
value={values.NewPassword}
onChange={handleChange}
/>
<div className="invalid-feedback">
{errors.NewPassword}
</div>
</div>
<div className="col-md-12">
<input
type="password"
className={`form-control ${errors.ConfirmPassword && touched.ConfirmPassword ? 'is-invalid' : ''}`}
placeholder="Enter Confirm Password"
name="ConfirmPassword"
value={values.ConfirmPassword}
onChange={handleChange}
/>
<div className="invalid-feedback">
{errors.ConfirmPassword}
</div>
</div>
<div className="col-12 text-end">
<button disabled={loading} className='btn btn-primary'>Change Password</button>
</div>
</div>
</form>
</div>
</div>
</>
)
}
Loading

0 comments on commit b5583a0

Please sign in to comment.