Skip to content

Commit

Permalink
Add missing ChangeOrgMemberRoleModal component
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed Jun 10, 2024
1 parent 739524f commit f927958
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions frontend/src/lib/components/Orgs/ChangeOrgMemberRoleModal.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script lang="ts">
import { FormModal, type FormModalResult } from '$lib/components/modals';
import { OrgRoleSelect, tryParse } from '$lib/forms';
import { OrgRole } from '$lib/gql/types';
import { _changeOrgMemberRole } from './mutations';
import t from '$lib/i18n';
import { z } from 'zod';
export let orgId: string;
$: schema = z.object({
role: z.enum([OrgRole.User, OrgRole.Admin])
});
type Schema = typeof schema;
let formModal: FormModal<Schema>;
$: form = formModal?.form();
let name: string;
export async function open(member: { userId: string; name: string; role: OrgRole }): Promise<FormModalResult<Schema>> {
name = member.name;
return await formModal.open(tryParse(schema, member), async () => {
const result = await _changeOrgMemberRole(
orgId,
member.userId,
$form.role,
);
return result.error?.message;
});
}
</script>

<FormModal bind:this={formModal} {schema} let:errors>
<span slot="title">{$t('org_page.change_role_modal.title', { name })}</span>
<OrgRoleSelect verbose bind:value={$form.role} error={errors.role} />
<span slot="submitText">{$t('org_page.change_role_modal.button_label')}</span>
</FormModal>

0 comments on commit f927958

Please sign in to comment.