-
-
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
e8ac64c
commit c7a6955
Showing
17 changed files
with
554 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; |
152 changes: 152 additions & 0 deletions
152
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,152 @@ | ||
import { OrganizationInvitationStatus } from '@logto/schemas'; | ||
import { format } from 'date-fns'; | ||
import { useContext, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import useSWR from 'swr'; | ||
|
||
import Plus from '@/assets/icons/plus.svg'; | ||
import UsersEmptyDark from '@/assets/images/users-empty-dark.svg'; | ||
import UsersEmpty from '@/assets/images/users-empty.svg'; | ||
import { useAuthedCloudApi } from '@/cloud/hooks/use-cloud-api'; | ||
import { type TenantInvitationResponse } from '@/cloud/types/router'; | ||
import ActionsButton from '@/components/ActionsButton'; | ||
import { RoleOption } from '@/components/OrganizationRolesSelect'; | ||
import { TenantsContext } from '@/contexts/TenantsProvider'; | ||
import Button from '@/ds-components/Button'; | ||
import Table from '@/ds-components/Table'; | ||
import TablePlaceholder from '@/ds-components/Table/TablePlaceholder'; | ||
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 } }) | ||
); | ||
|
||
const [showInviteModal, setShowInviteModal] = useState(false); | ||
|
||
return ( | ||
<> | ||
<Table | ||
isRowHoverEffectDisabled | ||
placeholder={ | ||
<TablePlaceholder | ||
image={<UsersEmpty />} | ||
imageDark={<UsersEmptyDark />} | ||
title="tenant_members.invitation_empty_placeholder.title" | ||
description="tenant_members.invitation_empty_placeholder.description" | ||
action={ | ||
<Button | ||
title="tenant_members.invite_member" | ||
type="primary" | ||
size="large" | ||
icon={<Plus />} | ||
onClick={() => { | ||
setShowInviteModal(true); | ||
}} | ||
/> | ||
} | ||
/> | ||
} | ||
isLoading={isLoading} | ||
errorMessage={error?.toString()} | ||
rowGroups={[{ key: 'data', data }]} | ||
columns={[ | ||
{ | ||
dataIndex: 'user', | ||
colSpan: 4, | ||
title: t('user'), | ||
render: ({ invitee }) => <span>{invitee}</span>, | ||
}, | ||
{ | ||
dataIndex: 'roles', | ||
colSpan: 4, | ||
title: t('roles'), | ||
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', | ||
colSpan: 4, | ||
title: t('invitation_status'), | ||
render: ({ status }) => ( | ||
<Tag type="state" status={convertInvitationStatusToTagStatus(status)}> | ||
{status} | ||
</Tag> | ||
), | ||
}, | ||
{ | ||
dataIndex: 'sentAt', | ||
colSpan: 4, | ||
title: t('invitation_sent'), | ||
render: ({ createdAt }) => <span>{format(createdAt, 'MMM Lo, yyyy')}</span>, | ||
}, | ||
{ | ||
dataIndex: 'expiresAt', | ||
colSpan: 4, | ||
title: t('expiration_date'), | ||
render: ({ expiresAt }) => <span>{format(expiresAt, 'MMM Lo, yyyy')}</span>, | ||
}, | ||
{ | ||
dataIndex: 'actions', | ||
title: null, | ||
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" | ||
/> | ||
{/* TODO: Implemented in the follow-up PR */} | ||
{/* {showInviteModal && <InviteModal isOpen={showInviteModal} />} */} | ||
</> | ||
); | ||
} | ||
|
||
export default Invitations; |
Oops, something went wrong.