User Settings
At this section you will find all personal settings. Some of them are standalone features, you can navigate to them through link bellow.
Last updated
At this section you will find all personal settings. Some of them are standalone features, you can navigate to them through link bellow.
Last updated
User settings have their own page. You can access it from this menu.
or by typing
http://your_website/user-settings
Go there and look at what setting do you have. Simple settings with switchers but all the mechanics you can learn from separate blocks.
What can be mentioned is the function that handles the request based on what switcher we switch.
The handleSwitchChange
is universal function that manages the behavior when a switch toggle is changed, updating settings and notifying the user accordingly. You can apply it every new switcher but edit the switch logic inside.
Here’s a breakdown of how it works:
Set Loading State: It first sets a loading state specific to the type (e.g., 'impersonationAllowed' or 'tourCompleted'), so the UI can show loading feedback for the action in progress.
Process Switch Type: The function checks the type to determine which action to perform:
If the type is impersonationAllowed, it calls updateProfile to update the user's profile with the new value.
If the type is tourCompleted, it calls updateUserTourStatus to update the tour status and then fetches the updated user data by calling fetchUser().
Update Options: After successfully executing the action, it updates the options state by setting the value of the corresponding type in the options object.
Show Success Notification: Upon successful completion, it displays a global success notification, retrieving translated message and description strings via t.
Handle Errors: If an error occurs:
It captures the error code from the response (err.response.data?.code).
It displays a global error notification with a message and description based on the error code.
Unset Loading State: Finally, it resets the loading state for the type to false in the finally block, ensuring that loading stops regardless of success or error.