Skip to content

Commit

Permalink
Added toast popup, blocks drivers from switching roles in a group
Browse files Browse the repository at this point in the history
  • Loading branch information
matherg committed Dec 2, 2024
1 parent c458bf5 commit 69860fb
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/pages/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,19 @@ const Index: NextPage = () => {
});
trackProfileCompletion(userInfo.role, userInfo.status);
};

const handleRoleChange = (newRole: Role) => {
if (
user?.role === Role.DRIVER &&
user.carpoolId &&
newRole !== Role.DRIVER
) {
toast.error(
"You are currently in a carpool group. To switch roles, please leave the group."
);
} else {
setValue("role", newRole, { shouldValidate: true });
}
};
if (isLoading || !user) {
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-white ">
Expand Down Expand Up @@ -208,25 +220,30 @@ const Index: NextPage = () => {
role={Role.VIEWER}
value={Role.VIEWER}
currentlySelected={watch("role")}
{...register("role")}
onChange={() => handleRoleChange(Role.VIEWER)}
checked={watch("role") === Role.VIEWER}
/>

<Radio
label="Rider"
id="rider"
error={errors.role}
role={Role.RIDER}
value={Role.RIDER}
currentlySelected={watch("role")}
{...register("role")}
onChange={() => handleRoleChange(Role.RIDER)}
checked={watch("role") === Role.RIDER}
/>

<Radio
label="Driver"
id="driver"
error={errors.role}
role={Role.DRIVER}
value={Role.DRIVER}
currentlySelected={watch("role")}
{...register("role")}
onChange={() => handleRoleChange(Role.DRIVER)}
checked={watch("role") === Role.DRIVER}
/>

{watch("role") == Role.DRIVER && (
Expand Down

0 comments on commit 69860fb

Please sign in to comment.