+ {user.username} |
+ {user.email} |
+ {user.role} |
+
+ {
+ open(event);
+ form.setValues(user);
+ setModalState('update');
+ }}
+ >
+
+
+ |
+
+ openDeleteModal(user)}>
+
+
+ |
+
+ ));
+};
+
const Users = () => {
const [modalState, setModalState] = useState('add');
- const [users, setUsers] = useState([]);
+ const [users, setUsers] = useState(useLoaderData());
const [skip, setSkip] = useState(SKIP);
const [showMore, setShowMore] = useState(true);
const [success, setSuccess] = useState(false);
const [error, setError] = useState(null);
const [opened, { open, close }] = useDisclosure(false);
- const [isLoading, setIsLoading] = useState(true);
- const [userError, setUserError] = useState(null);
const { t } = useTranslation();
const defaultValues = {
username: '',
email: '',
- role: '',
+ role: 'user',
password: '',
};
const form = useForm({
- initialValues: defaultValues,
+ initialValues: users,
});
- useEffect(() => {
- (async () => {
- try {
- const users = await getUsers();
-
- if (users.error || [401, 403, 500].includes(users.statusCode)) {
- setUserError(users.error ? users.error : t('not_logged_in'));
-
- return;
- }
-
- if (users?.length < SKIP) {
- setShowMore(false);
- }
-
- if (!users?.error) {
- setUsers(users);
- }
-
- setIsLoading(false);
- setUserError(null);
- } catch (err) {
- setUserError(err);
- }
- })();
- }, []);
+ if (users?.length < SKIP) {
+ setShowMore(false);
+ }
const onUpdateUser = async (event) => {
event.preventDefault();
@@ -224,40 +226,9 @@ const Users = () => {
close(event);
};
- const rows = users.map((user) => (
-