Skip to content

Commit

Permalink
use simpler hook closer to the usage
Browse files Browse the repository at this point in the history
  • Loading branch information
magicznyleszek committed Dec 2, 2024
1 parent 88544bf commit b601abe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
13 changes: 7 additions & 6 deletions jsapp/js/account/organization/MemberRoleSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Partial components
import KoboSelect from 'jsapp/js/components/common/koboSelect';

// Constants and types
import {usePatchOrganizationMember} from './membersQuery';
import {OrganizationUserRole} from './organizationQuery';

interface MemberRoleSelectorProps {
orgId: string;
username: string;
role: OrganizationUserRole;
onRequestRoleChange: (username: string, role: OrganizationUserRole) => void;
}

export default function MemberRoleSelector(
{username, role, onRequestRoleChange}: MemberRoleSelectorProps
{orgId, username, role}: MemberRoleSelectorProps
) {
const patchMember = usePatchOrganizationMember(orgId, username);

return (
<KoboSelect
name={`member-role-selector-${username}`}
Expand All @@ -31,9 +31,10 @@ export default function MemberRoleSelector(
selectedOption={role}
onChange={(newRole: string | null) => {
if (newRole !== null) {
onRequestRoleChange(username, newRole as OrganizationUserRole);
patchMember.mutateAsync({role: newRole as OrganizationUserRole});
}
}}
isPending={patchMember.isPending}
/>
);
}
16 changes: 2 additions & 14 deletions jsapp/js/account/organization/MembersRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import MemberRoleSelector from './MemberRoleSelector';
// Stores, hooks and utilities
import {formatTime} from 'js/utils';
import {OrganizationUserRole, useOrganizationQuery} from './organizationQuery';
import useOrganizationMembersQuery, {usePatchOrganizationMember} from './membersQuery';
import useOrganizationMembersQuery from './membersQuery';

// Constants and types
import type {OrganizationMember} from './membersQuery';
Expand All @@ -22,7 +22,6 @@ import styles from './membersRoute.module.scss';

export default function MembersRoute() {
const orgQuery = useOrganizationQuery();
const patchMember = usePatchOrganizationMember();

if (!orgQuery.data) {
return (
Expand Down Expand Up @@ -75,20 +74,9 @@ export default function MembersRoute() {
}
return (
<MemberRoleSelector
orgId={orgQuery.data.id}
username={member.user__username}
role={member.role}
onRequestRoleChange={
(
username: string,
newRole: OrganizationUserRole
) => {
patchMember.mutateAsync({
orgId: orgQuery.data.id,
username: username,
newMemberData: {role: newRole},
});
}
}
/>
);
}
Expand Down

0 comments on commit b601abe

Please sign in to comment.