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

Updating Auth-Dependent UI Elements #34

Merged
merged 5 commits into from
Feb 13, 2024

Conversation

v-sokolic
Copy link
Contributor

@v-sokolic v-sokolic commented Feb 9, 2024

closes #33

Copy link

netlify bot commented Feb 9, 2024

Deploy Preview for wine-control ready!

Name Link
🔨 Latest commit faf87b2
🔍 Latest deploy log https://app.netlify.com/sites/wine-control/deploys/65c63597d65cc100086935bf
😎 Deploy Preview https://deploy-preview-34--wine-control.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@v-sokolic v-sokolic changed the base branch from main to development February 9, 2024 14:24
Copy link

netlify bot commented Feb 9, 2024

Deploy Preview for keen-syrniki-6d7c39 ready!

Name Link
🔨 Latest commit faf87b2
🔍 Latest deploy log https://app.netlify.com/sites/keen-syrniki-6d7c39/deploys/65c635970b06cc00088d94f4
😎 Deploy Preview https://deploy-preview-34--keen-syrniki-6d7c39.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@v-sokolic v-sokolic linked an issue Feb 9, 2024 that may be closed by this pull request
3 tasks
try {
await logout();
} catch (error) {
console.error('Logout error:', error);
Copy link
Contributor

@ivbrajkovic ivbrajkovic Feb 9, 2024

Choose a reason for hiding this comment

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

Consider using the Mantine notification system, as implemented in issue #7. For examples of its usage, please refer to the corresponding branch.

For additional reference, visit:
https://mantine.dev/x/notifications/

const userLoggedIn = useIsAuthenticated();

const userInitials =
userDetails?.name && userDetails?.lastname
Copy link
Contributor

@ivbrajkovic ivbrajkovic Feb 9, 2024

Choose a reason for hiding this comment

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

Please extract this into a function getUserInitials

)}
</AppShell.Section>

{userLoggedIn && (
Copy link
Contributor

@ivbrajkovic ivbrajkovic Feb 9, 2024

Choose a reason for hiding this comment

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

No need for this check, if user initials are falsy than default avatar picture will be shown

// TODO: Replace with the actual user data
const userInitials = 'JD';
const { userUid } = useAuthService();
const { data: userDetails } = useGetUserDetailsQuery(userUid ?? skipToken);
Copy link
Contributor

@ivbrajkovic ivbrajkovic Feb 9, 2024

Choose a reason for hiding this comment

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

Every query hooks has two data object data and currentData. Use currenData with skipToken, because if userUid became falsy data wil contain last query result from cache, but currenData cache will be cleared.

For additional reference, visit:
reduxjs/redux-toolkit#3188
https://redux-toolkit.js.org/rtk-query/api/created-api/hooks#usequery

Copy link
Contributor

@ivbrajkovic ivbrajkovic left a comment

Choose a reason for hiding this comment

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

Request for revision

Copy link
Contributor

@ivbrajkovic ivbrajkovic left a comment

Choose a reason for hiding this comment

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

resolve #33

@@ -56,12 +65,18 @@ export const NavigationBar = () => {
<NavLink
label="Home"
leftSection={<IconHome2 />}
onClick={juxt([toggleSidebar, goDashboard])}
onClick={
userLoggedIn ? juxt([toggleSidebar, goDashboard]) : undefined
Copy link
Contributor

@ivbrajkovic ivbrajkovic Feb 12, 2024

Choose a reason for hiding this comment

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

Use disabled prop

onClick={
userLoggedIn ? juxt([toggleSidebar, goDashboard]) : undefined
}
style={!userLoggedIn ? { color: 'gray' } : undefined}
Copy link
Contributor

@ivbrajkovic ivbrajkovic Feb 12, 2024

Choose a reason for hiding this comment

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

No need for this if you use disabled prop

/>
<NavLink
label="Settings"
leftSection={<IconSettings />}
onClick={juxt([toggleSidebar, goSettings])}
onClick={
Copy link
Contributor

Choose a reason for hiding this comment

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

Use disabled prop

onClick={
userLoggedIn ? juxt([toggleSidebar, goSettings]) : undefined
}
style={!userLoggedIn ? { color: 'gray' } : undefined}
Copy link
Contributor

@ivbrajkovic ivbrajkovic Feb 12, 2024

Choose a reason for hiding this comment

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

No need for this if you use disabled prop

userUid ?? skipToken,
);

const { currentData: userLoggedIn } = useGetAuthStateQuery();
Copy link
Contributor

Choose a reason for hiding this comment

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

Use data, as currentData is only and maybe useful when skipToken or skip option is used.
As the data returned from hook is an object or undefined and if you need a boolean check its a good practice for clean stile to init new variable, for example:

const isLoggedIn = Boolean(data);

import { useSidebar } from 'features/layout/hooks/useSidebar';

export const Header = () => {
const [isOpen, toggleSidebar] = useSidebar();
const [logout] = useLogoutMutation();
const { currentData: userLoggedIn } = useGetAuthStateQuery();
Copy link
Contributor

Choose a reason for hiding this comment

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

Use data, as currentData is only and maybe useful when skipToken or skip option is used.
As the data returned from hook is an object or undefined and if you need a boolean check its a good practice for clean stile to init new variable, for example:

const isLoggedIn = Boolean(data);

@ivbrajkovic ivbrajkovic merged commit cbfd415 into development Feb 13, 2024
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.

Update Auth-Dependent UI Elements
2 participants