Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak(adminPanel): RN-1295: Update auth screens on admin panel #5666

Merged
merged 37 commits into from
Jun 9, 2024

Conversation

alexd-bes
Copy link
Contributor

Issue RN-1295: Update auth screens on admin panel

Changes:

  • Updated auth handling in admin panel to use react-query so it is easier to handle the auth flow
  • Updated login screen to use common login form
  • Added forgot password and reset password views
  • Updated LESMIS admin panel to match

Screenshots:

Screen Shot 2024-05-23 at 2 53 02 PM
Screen Shot 2024-05-23 at 2 53 07 PM
Screen Shot 2024-05-23 at 2 53 34 PM
Screen Shot 2024-05-23 at 2 53 55 PM

Copy link
Contributor

@jaskfla jaskfla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More lines removed than added! 🤩

So much neater with TanStack Query—thanks for making that shift. I think my only substantial comment is about whether useUser should be a query hook or in a context. I’m also not sure if it’s change-worthy, so pre-approving regardless

The rest are just nitpicks

Comment on lines 12 to 24
return useMutation(
'updateProfile',
payload => {
return put('me', {
data: payload,
});
},
{
onSuccess: () => {
queryClient.invalidateQueries(['user']);
},
},
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question, sorry, what overload of useMutation is this? I trust it works, but can’t find it in the docs; I would’ve thought it’d need to look like

useMutation(
  payload => put(...),
  {
    mutationKey: 'updateProfile',
    onSuccess: () => {...},
  }
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I don't think it does anything, you're right. I will just remove, since we don't really need it sticking around anyway

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, this is clever

Though, is this something we would want in a context instead, like in DataTrak? Doesn’t look too tricky to figure out that, with this implementation, we’d just guard things behind isLoggedIn && ...; but I think if we can throw an error (and/or redirect to /login) when initialising a LoggedInUserContext it could guarantee a defined user

Not sure if that will disagree with other bits of the setup, though

import { WHITE } from '../../theme/colors';

export const UserLink = styled(Link)`
font-size: 0.6875rem;
export const UserLink = styled(Button).attrs({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, is it redundant to set both the color prop and CSS property?

I presume one trumps the other, but just reading it I’m not sure which

{errorMessage && <ErrorMessage>{errorMessage}</ErrorMessage>}
{successMessage && <SuccessMessage>{successMessage}</SuccessMessage>}
{error && <ErrorMessage>{error.message}</ErrorMessage>}
{isSuccess && <SuccessMessage>Password successfully updated.</SuccessMessage>}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense for this page to just regurgitate the success message from the backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It definitely could, I was just copying over the existing logic

Comment on lines 75 to 76
<TextField
label="New Password"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<TextField
label="New Password"
<TextField
autoComplete="new-password"
label="New Password"

Autocomplete value for newPasswordConfirm would be identical

Comment on lines 62 to 63
<TextField
label="Current Password"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<TextField
label="Current Password"
<TextField
autoComplete="current-password"
label="Current Password"

@@ -113,7 +93,7 @@ const ProfilePageComponent = React.memo(({ user, onUpdateProfile }) => {
<Divider />
<TextField
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given-name & family-name autocomplete values could also apply here ⚡

@@ -180,7 +180,7 @@ const DataFetchingTableComponent = ({
}
gotoPage(0);
setSortBy(defaultSorting ?? []); // reset sorting when table is re-initialised
}, [endpoint, baseFilter]);
}, [endpoint, JSON.stringify(baseFilter)]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this affect the behaviour of useEffect? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseFilter will be an object, and often if you pass in a nested object, checking the equality causes infinite re-renders and bugs. So stringifying it will stop that happening

Comment on lines +89 to +94
Don&rsquo;t have an account?{' '}
{RegisterLinkComponent ? (
RegisterLinkComponent
) : (
<RouterLink to={registerLink}>Sign up</RouterLink>
)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This almost certainly fails Prettier formatting, but:

Suggested change
Don&rsquo;t have an account?{' '}
{RegisterLinkComponent ? (
RegisterLinkComponent
) : (
<RouterLink to={registerLink}>Sign up</RouterLink>
)}
Don&rsquo;t have an account?{' '}
{RegisterLinkComponent ?? <RouterLink to={registerLink}>Sign up</RouterLink>}

@alexd-bes alexd-bes merged commit 7e402a5 into dev Jun 9, 2024
44 checks passed
@alexd-bes alexd-bes deleted the rn-1295-login-screen branch June 9, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants