-
-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): add tenant member and invitation lists
- Loading branch information
1 parent
431c202
commit d65f226
Showing
17 changed files
with
523 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/console/src/pages/TenantSettings/TenantMembers/EditMemberModal/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { TenantRole } from '@logto/schemas'; | ||
import { getUserDisplayName } from '@logto/shared/universal'; | ||
import { useContext, useMemo, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import ReactModal from 'react-modal'; | ||
import { z } from 'zod'; | ||
|
||
import { useAuthedCloudApi } from '@/cloud/hooks/use-cloud-api'; | ||
import { type TenantMemberResponse } from '@/cloud/types/router'; | ||
import { TenantsContext } from '@/contexts/TenantsProvider'; | ||
import Button from '@/ds-components/Button'; | ||
import FormField from '@/ds-components/FormField'; | ||
import ModalLayout from '@/ds-components/ModalLayout'; | ||
import Select from '@/ds-components/Select'; | ||
import * as modalStyles from '@/scss/modal.module.scss'; | ||
|
||
type Props = { | ||
user: TenantMemberResponse; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
}; | ||
|
||
function EditMemberModal({ user, isOpen, onClose }: Props) { | ||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.tenant_members' }); | ||
const { currentTenantId } = useContext(TenantsContext); | ||
|
||
const [isLoading, setIsLoading] = useState(false); | ||
const [role, setRole] = useState(TenantRole.Member); | ||
const cloudApi = useAuthedCloudApi(); | ||
|
||
const roleOptions = useMemo( | ||
() => [ | ||
{ value: TenantRole.Admin, title: t('admin') }, | ||
{ value: TenantRole.Member, title: t('member') }, | ||
], | ||
[t] | ||
); | ||
|
||
const onSubmit = async () => { | ||
setIsLoading(true); | ||
try { | ||
await cloudApi.put(`/api/tenants/:tenantId/members/:userId/roles`, { | ||
params: { tenantId: currentTenantId, userId: user.id }, | ||
body: { roleName: role }, | ||
}); | ||
onClose(); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<ReactModal | ||
isOpen={isOpen} | ||
className={modalStyles.content} | ||
overlayClassName={modalStyles.overlay} | ||
onRequestClose={onClose} | ||
> | ||
<ModalLayout | ||
title={<>{t('edit_modal.title', { name: getUserDisplayName(user) })}</>} | ||
footer={ | ||
<Button | ||
size="large" | ||
type="primary" | ||
title="general.save" | ||
isLoading={isLoading} | ||
onClick={onSubmit} | ||
/> | ||
} | ||
onClose={onClose} | ||
> | ||
<FormField title="tenant_members.roles"> | ||
<Select | ||
options={roleOptions} | ||
value={role} | ||
onChange={(value) => { | ||
const guardResult = z.nativeEnum(TenantRole).safeParse(value); | ||
setRole(guardResult.success ? guardResult.data : TenantRole.Member); | ||
}} | ||
/> | ||
</FormField> | ||
</ModalLayout> | ||
</ReactModal> | ||
); | ||
} | ||
|
||
export default EditMemberModal; |
121 changes: 121 additions & 0 deletions
121
packages/console/src/pages/TenantSettings/TenantMembers/Invitations/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { OrganizationInvitationStatus } from '@logto/schemas'; | ||
import { format } from 'date-fns'; | ||
import { useContext } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import useSWR from 'swr'; | ||
|
||
import { useAuthedCloudApi } from '@/cloud/hooks/use-cloud-api'; | ||
import { type TenantInvitationResponse } from '@/cloud/types/router'; | ||
import ActionsButton from '@/components/ActionsButton'; | ||
import EmptyDataPlaceholder from '@/components/EmptyDataPlaceholder'; | ||
import { RoleOption } from '@/components/OrganizationRolesSelect'; | ||
import { TenantsContext } from '@/contexts/TenantsProvider'; | ||
import Table from '@/ds-components/Table'; | ||
import Tag from '@/ds-components/Tag'; | ||
import { type RequestError } from '@/hooks/use-api'; | ||
|
||
const convertInvitationStatusToTagStatus = (status: OrganizationInvitationStatus) => { | ||
switch (status) { | ||
case OrganizationInvitationStatus.Pending: { | ||
return 'alert'; | ||
} | ||
case OrganizationInvitationStatus.Accepted: { | ||
return 'success'; | ||
} | ||
case OrganizationInvitationStatus.Revoked: { | ||
return 'error'; | ||
} | ||
default: { | ||
return 'info'; | ||
} | ||
} | ||
}; | ||
|
||
function Invitations() { | ||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.tenant_members' }); | ||
const cloudApi = useAuthedCloudApi(); | ||
const { currentTenantId } = useContext(TenantsContext); | ||
|
||
const { data, error, isLoading, mutate } = useSWR<TenantInvitationResponse[], RequestError>( | ||
`api/tenant/${currentTenantId}/invitations`, | ||
async () => | ||
cloudApi.get('/api/tenants/:tenantId/invitations', { params: { tenantId: currentTenantId } }) | ||
); | ||
|
||
return ( | ||
<Table | ||
isRowHoverEffectDisabled | ||
placeholder={<EmptyDataPlaceholder />} | ||
isLoading={isLoading} | ||
errorMessage={error?.toString()} | ||
rowGroups={[{ key: 'data', data }]} | ||
columns={[ | ||
{ | ||
dataIndex: 'user', | ||
title: t('user'), | ||
render: ({ invitee }) => <span>{invitee}</span>, | ||
}, | ||
{ | ||
dataIndex: 'roles', | ||
title: t('roles'), | ||
colSpan: 1, | ||
render: ({ organizationRoles }) => { | ||
if (organizationRoles.length === 0) { | ||
return '-'; | ||
} | ||
|
||
return organizationRoles.map(({ id, name }) => ( | ||
<Tag key={id} variant="cell"> | ||
<RoleOption value={id} title={name} /> | ||
</Tag> | ||
)); | ||
}, | ||
}, | ||
{ | ||
dataIndex: 'status', | ||
title: t('user'), | ||
render: ({ status }) => ( | ||
<Tag variant="cell" status={convertInvitationStatusToTagStatus(status)}> | ||
{status} | ||
</Tag> | ||
), | ||
}, | ||
{ | ||
dataIndex: 'sentAt', | ||
title: t('user'), | ||
render: ({ createdAt }) => <span>{format(createdAt, 'MMM Lo, yyyy')}</span>, | ||
}, | ||
{ | ||
dataIndex: 'expiresAt', | ||
title: t('user'), | ||
render: ({ expiresAt }) => <span>{format(expiresAt, 'MMM Lo, yyyy')}</span>, | ||
}, | ||
{ | ||
dataIndex: 'actions', | ||
title: null, | ||
colSpan: 1, | ||
render: (invitation) => ( | ||
<ActionsButton | ||
deleteConfirmation="tenant_members.delete_user_confirm" | ||
fieldName="tenant_members.user" | ||
textOverrides={{ | ||
edit: 'tenant_members.menu_options.resend_invite', | ||
delete: 'tenant_members.menu_options.revoke', | ||
deleteConfirmation: 'general.remove', | ||
}} | ||
onDelete={async () => { | ||
await cloudApi.delete(`/api/tenants/:tenantId/invitations/:invitationId`, { | ||
params: { tenantId: currentTenantId, invitationId: invitation.id }, | ||
}); | ||
void mutate(); | ||
}} | ||
/> | ||
), | ||
}, | ||
]} | ||
rowIndexKey="id" | ||
/> | ||
); | ||
} | ||
|
||
export default Invitations; |
Oops, something went wrong.