This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
User Management UI #511
Merged
Merged
User Management UI #511
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
b371ae1
Start setup on user management feature
e2dc6e6
User form
1913522
Add set-up for some actions and profile page with form
c885721
Work on new user
533ecf1
Update row
04a1a2e
Clean-up navbar
037c892
Set active classnames in nav links
eb9caa4
Add privileges
c8913a2
Cancel functionality on new user form
abd4c58
User slice
f8a7d7d
Delete user modal
b04cad5
Breadcrumbs and delete user modal as menuitem
271e21b
User POST in slice
f6697b1
Update slice
843f7fb
Create through slice
058dcd2
Set-up for future api work
0d16ed1
Merge commit
e19867e
Start get
e06a03c
Create and Delete set-up
fc0f8cd
Delete user validation
fe019ef
Amend
fafaae1
Merge branch 'main' into user-management
4256fed
User search
e1aa443
Edit tweaks
ae4a365
Merge branch 'main' into user-management
f62e286
User privileges
2cf9d3f
Ui tweaks
b2ac302
Permissions
14a24d4
Merge branch 'main' into user-management
4dcda8c
Add additional user info to table
90b4f36
Checkboxes
74cec89
Some small form fixes
8ce4ed8
Refreshes and checkboxes on load
7260bc9
Default values
266038b
Merge branch 'main' into user-management
7efd4a2
Split out edit and new forms for easier flow and initial value in for…
0483358
Type checking
b0665a5
Some file cleanup
7fd6a8a
Pagination;
c14dcce
Some style tweaks
ec15cfd
Change checkbox color
498fabc
Merge branch 'main' into user-management
e71f02a
Merge branch 'main' into user-management
3eb706d
Checkboxes
38de125
Cleanup
fc3663d
Remove unused effect
32b5ad7
Merge branch 'main' into user-management
f0a9d8f
Update session with user info and fix client console warning for cont…
c9dae35
Update session in pages
29a2f76
Some form cleanup
828ca39
Clean index page
dd434ae
Edit user permissions checks
902cfa2
Feedback
e3b2cab
Merge branch 'main' into user-management
LKCSmith 6481300
Remove duplicate
9e8904d
Fix checkbox bug
466ee12
Password update
39eb499
Add error handling on new user form
eec5934
Change password modal
06c0377
Remove rogue console
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ import { | |
Input, | ||
Stack, | ||
Text, | ||
useToast, | ||
} from '@fidesui/react'; | ||
import config from './config/config.json'; | ||
import { | ||
|
@@ -31,6 +32,7 @@ const useUserForm = () => { | |
const [updateUserPermissions, updateUserPermissionsResult] = | ||
useUpdateUserPermissionsMutation(); | ||
const router = useRouter(); | ||
const toast = useToast(); | ||
|
||
const formik = useFormik({ | ||
initialValues: { | ||
|
@@ -53,27 +55,39 @@ const useUserForm = () => { | |
password: values.password, | ||
}; | ||
|
||
await createUser(userBody) | ||
.then((result) => { | ||
const userWithPrivileges = { | ||
id: 'data' in result ? result.data.id : null, | ||
scopes: [...values.scopes, 'privacy-request:read'], | ||
}; | ||
const { error: createUserError, data } = await createUser(userBody); | ||
|
||
return userWithPrivileges; | ||
}) | ||
.then((result) => { | ||
const permissionsToAddToUser = updateUserPermissions( | ||
result as { id: string } | ||
); | ||
if (createUserError) { | ||
toast({ | ||
status: 'error', | ||
description: createUserError.data.detail.length | ||
? `${createUserError.data.detail[0].msg}` | ||
: 'An unexpected error occurred. Please try again.', | ||
}); | ||
return; | ||
} | ||
|
||
if (createUserError && createUserError.status == 422) { | ||
toast({ | ||
status: 'error', | ||
description: createUserError.data.detail.length | ||
? `${createUserError.data.detail[0].msg}` | ||
: 'An unexpected error occurred. Please try again.', | ||
}); | ||
} | ||
|
||
const userWithPrivileges = { | ||
id: data ? data.id : null, | ||
scopes: [...values.scopes, 'privacy-request:read'], | ||
}; | ||
|
||
const { error: updatePermissionsError } = await updateUserPermissions( | ||
userWithPrivileges as { id: string } | ||
); | ||
|
||
return permissionsToAddToUser; | ||
}) | ||
.then((result) => { | ||
router.replace('/user-management'); | ||
return result; | ||
}) | ||
.catch((error) => console.log('ERROR', error)); | ||
if (!updatePermissionsError) { | ||
router.push('/user-management'); | ||
} | ||
}, | ||
validate: (values) => { | ||
const errors: { | ||
|
@@ -91,7 +105,25 @@ const useUserForm = () => { | |
errors.password = 'Password is required'; | ||
} | ||
|
||
// 422 password validation | ||
if (values.password.length < 8) { | ||
errors.password = 'Password must have at least eight characters.'; | ||
} | ||
|
||
if (!/[0-9]/.test(values.password)) { | ||
errors.password = 'Password must have at least one number.'; | ||
} | ||
|
||
if (!/[A-Z]/.test(values.password)) { | ||
errors.password = 'Password must have at least one capital letter.'; | ||
} | ||
|
||
if (!/[a-z]/.test(values.password)) { | ||
errors.password = 'Password must have at least one lowercase letter.'; | ||
} | ||
|
||
if (!/[\W]/.test(values.password)) { | ||
errors.password = 'Password must have at least one symbol.'; | ||
} | ||
|
||
return errors; | ||
}, | ||
|
@@ -246,7 +278,7 @@ const UserForm: NextPage = () => { | |
_hover={{ bg: 'primary.400' }} | ||
_active={{ bg: 'primary.500' }} | ||
colorScheme="primary" | ||
disabled={!(isValid && dirty)} | ||
// disabled={!(isValid && dirty)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be removed? |
||
size="sm" | ||
> | ||
Save | ||
|
118 changes: 118 additions & 0 deletions
118
clients/admin-ui/src/features/user-management/UpdatePasswordModal.tsx
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,118 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
Button, | ||
FormControl, | ||
Input, | ||
MenuItem, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
Stack, | ||
Text, | ||
useDisclosure, | ||
} from '@fidesui/react'; | ||
|
||
import { User } from '../user/types'; | ||
import { useUpdatePasswordMutation } from '../user/user.slice'; | ||
|
||
function UpdatePasswordModal(user: User) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how come we don't use formik for this one? It's simpler than the other form, but for handling errors and such, may still want to go through formik |
||
const [oldPasswordValue, setOldPasswordValue] = useState(''); | ||
const [newPasswordValue, setNewPasswordValue] = useState(''); | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const [changePassword, changePasswordResult] = useUpdatePasswordMutation(); | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
if (event.target.name === 'username') { | ||
setUsernameValue(event.target.value); | ||
} else { | ||
setConfirmValue(event.target.value); | ||
} | ||
}; | ||
|
||
const deletionValidation = | ||
user.id && | ||
confirmValue && | ||
usernameValue && | ||
user.username === usernameValue && | ||
user.username === confirmValue | ||
? true | ||
: false; | ||
|
||
const handleDeleteUser = () => { | ||
if (deletionValidation && user.id) { | ||
deleteUser(user.id); | ||
onClose(); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<MenuItem | ||
_focus={{ color: 'complimentary.500', bg: 'gray.100' }} | ||
onClick={onOpen} | ||
> | ||
<Text fontSize="sm">Update Password</Text> | ||
</MenuItem> | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Update Password</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody pb={6}> | ||
<Stack direction={'column'} spacing="15px"> | ||
<FormControl> | ||
<Input | ||
isRequired | ||
name="oldPassword" | ||
onChange={handleChange} | ||
placeholder="Old Password" | ||
value={usernameValue} | ||
/> | ||
</FormControl> | ||
<FormControl> | ||
<Input | ||
isRequired | ||
name="newPassword" | ||
onChange={handleChange} | ||
placeholder="New Password" | ||
value={confirmValue} | ||
/> | ||
</FormControl> | ||
</Stack> | ||
</ModalBody> | ||
|
||
<ModalFooter> | ||
<Button | ||
onClick={onClose} | ||
marginRight={'10px'} | ||
size={'sm'} | ||
variant={'solid'} | ||
bg="white" | ||
width={'50%'} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
disabled={!passwordValidation} | ||
onClick={handleChangePassword} | ||
mr={3} | ||
size={'sm'} | ||
variant="solid" | ||
bg="primary.800" | ||
color="white" | ||
width={'50%'} | ||
> | ||
Change Password | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
} | ||
|
||
export default UpdatePasswordModal; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an example of how Yup would work for this logic: https://stackoverflow.com/questions/49502436/password-validation-with-yup-and-formik