Skip to content

Commit

Permalink
Merge pull request #1988 from quadratichq/jim-fix-optimistic-ui
Browse files Browse the repository at this point in the history
fix: optimistic UI when changing user role
  • Loading branch information
jimniels authored Oct 29, 2024
2 parents 0240d82 + 05aa3ab commit da5996c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions quadratic-client/src/shared/components/ShareDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,13 @@ function ManageUser({
let activeRole = user.role;
let error = undefined;

// If the user's role is being updated, show the optimistic value
if (fetcherUpdate.state !== 'idle' && isJsonObject(fetcherUpdate.json)) {
activeRole = fetcherUpdate.json.role as (typeof roles)[0];
} else if (fetcherUpdate.data && !fetcherUpdate.data.ok) {
error = 'Failed to update. Try again.';
}

const label = useMemo(() => getRoleLabel(activeRole), [activeRole]);

// If user is being deleted, hide them
Expand All @@ -658,13 +665,6 @@ function ManageUser({
error = 'Failed to delete. Try again.';
}

// If the user's role is being updated, show the optimistic value
if (fetcherUpdate.state !== 'idle' && isJsonObject(fetcherUpdate.json)) {
activeRole = fetcherUpdate.json.role as (typeof roles)[0];
} else if (fetcherUpdate.data && !fetcherUpdate.data.ok) {
error = 'Failed to update. Try again.';
}

return (
<ListItemUser
isYou={isLoggedInUser}
Expand Down

0 comments on commit da5996c

Please sign in to comment.