-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add initial tenants ui #3855
Merged
djabarovgeorge
merged 3 commits into
stacked-tenants-support
from
NV-2611-initial-tenants-page-ui
Jul 26, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { api } from './api.client'; | ||
|
||
export function getTenants() { | ||
return api.get('/v1/tenants'); | ||
} |
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,20 @@ | ||
import { UseQueryOptions, useQuery } from '@tanstack/react-query'; | ||
|
||
import { ITenantEntity } from '@novu/shared'; | ||
|
||
import { QueryKeys } from '../api/query.keys'; | ||
import { getTenants } from '../api/tenants'; | ||
|
||
export function useTenants(options: UseQueryOptions<ITenantEntity[], any, ITenantEntity[]> = {}) { | ||
const { data, isLoading, ...rest } = useQuery<ITenantEntity[], any, ITenantEntity[]>( | ||
[QueryKeys.tenantsList], | ||
getTenants, | ||
{ refetchOnMount: false, ...options } | ||
); | ||
|
||
return { | ||
tenants: data, | ||
loading: isLoading, | ||
...rest, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
import React, { useCallback } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import PageContainer from '../../components/layout/components/PageContainer'; | ||
import PageHeader from '../../components/layout/components/PageHeader'; | ||
import { TenantsList } from './components/list/TenantsList'; | ||
|
||
export function TenantsPage() { | ||
const navigate = useNavigate(); | ||
|
||
const onAddTenantClickCallback = useCallback(() => { | ||
// navigate(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we will navigate hit to the side bar that Gali is working on. |
||
}, [navigate]); | ||
|
||
return ( | ||
<PageContainer title="Tenants"> | ||
<PageHeader title="Tenants" /> | ||
<TenantsList onAddTenantClick={onAddTenantClickCallback} /> | ||
</PageContainer> | ||
); | ||
} |
33 changes: 30 additions & 3 deletions
33
apps/web/src/pages/tenants/components/list/TenantsList.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 |
---|---|---|
@@ -1,3 +1,30 @@ | ||
export function TenantsList() { | ||
return null; | ||
} | ||
import { Container } from '@mantine/core'; | ||
|
||
import { Table } from '../../../../design-system'; | ||
import PageContainer from '../../../../components/layout/components/PageContainer'; | ||
import { When } from '../../../../components/utils/When'; | ||
import { columns } from './columns'; | ||
import { useTenants } from '../../../../hooks/useTenants'; | ||
import { Toolbar } from './ToolBar'; | ||
|
||
export const TenantsList = ({ onAddTenantClick }: { onAddTenantClick: React.MouseEventHandler<HTMLButtonElement> }) => { | ||
const { tenants, loading } = useTenants(); | ||
const hasTenants = tenants && tenants?.length > 0; | ||
|
||
return ( | ||
<PageContainer | ||
style={{ | ||
position: 'relative', | ||
overflow: 'hidden', | ||
}} | ||
title="Tenants" | ||
> | ||
<Container fluid sx={{ padding: '0 30px 8px 30px' }}> | ||
<Toolbar onAddTenantClick={onAddTenantClick} tenantLoading={loading} /> | ||
</Container> | ||
<When truthy={hasTenants || loading}> | ||
<Table loading={loading} data-test-id="tenants-list-table" columns={columns} data={tenants || []} /> | ||
</When> | ||
</PageContainer> | ||
); | ||
}; |
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,49 @@ | ||
import styled from '@emotion/styled'; | ||
import React from 'react'; | ||
|
||
import { Button, Text } from '../../../../design-system'; | ||
|
||
const Holder = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
`; | ||
|
||
const ButtonStyled = styled(Button)` | ||
margin-left: -8px; | ||
`; | ||
|
||
const PlusSquare = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 24px; | ||
max-width: 24px; | ||
height: 24px; | ||
padding: 0; | ||
font-size: 18px; | ||
font-weight: 700; | ||
border-radius: 4px; | ||
`; | ||
|
||
export const Toolbar = ({ | ||
tenantLoading, | ||
onAddTenantClick, | ||
}: { | ||
tenantLoading: boolean; | ||
onAddTenantClick: React.MouseEventHandler<HTMLButtonElement>; | ||
}) => { | ||
return ( | ||
<Holder> | ||
<ButtonStyled | ||
id="add-tenant" | ||
onClick={onAddTenantClick} | ||
disabled={tenantLoading} | ||
data-test-id="add-tenant" | ||
variant="subtle" | ||
> | ||
<PlusSquare data-square>+</PlusSquare> | ||
<Text gradient>Add a tenant</Text> | ||
</ButtonStyled> | ||
</Holder> | ||
); | ||
}; |
djabarovgeorge marked this conversation as resolved.
Show resolved
Hide resolved
|
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,48 @@ | ||
import { format } from 'date-fns'; | ||
|
||
import { ITenantEntity } from '@novu/shared'; | ||
|
||
import { IExtendedColumn, Tooltip, withCellLoading, Text } from '../../../../design-system'; | ||
|
||
const maxWidth = 60; | ||
|
||
export const columns: IExtendedColumn<ITenantEntity>[] = [ | ||
{ | ||
accessor: 'name', | ||
Header: 'Name', | ||
Cell: withCellLoading(({ row: { original } }) => ( | ||
<Tooltip label={original.name}> | ||
<div> | ||
<Text rows={1}>{original.name || ''}</Text> | ||
</div> | ||
</Tooltip> | ||
)), | ||
}, | ||
{ | ||
accessor: 'identifier', | ||
Header: 'Tenant identifier', | ||
Cell: withCellLoading(({ row: { original } }) => ( | ||
<Tooltip label={original.name}> | ||
<div> | ||
<Text rows={1}>{original.name || ''}</Text> | ||
</div> | ||
</Tooltip> | ||
)), | ||
}, | ||
{ | ||
accessor: 'createdAt', | ||
Header: 'Created at', | ||
maxWidth: maxWidth, | ||
Cell: withCellLoading(({ row: { original }, isLoading }) => { | ||
return format(new Date(original.createdAt), 'dd/MM/yyyy HH:mm'); | ||
}), | ||
}, | ||
{ | ||
accessor: 'updatedAt', | ||
Header: 'Updated at', | ||
djabarovgeorge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
maxWidth: maxWidth, | ||
Cell: withCellLoading(({ row: { original }, isLoading }) => { | ||
return format(new Date(original.updatedAt), 'dd/MM/yyyy HH:mm'); | ||
}), | ||
}, | ||
]; |
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 @@ | ||
export * from './tenant.interface'; |
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,19 @@ | ||
import { EnvironmentId, TenantCustomData, TenantId } from '../../types'; | ||
|
||
export interface ITenantEntity { | ||
_id?: TenantId; | ||
|
||
identifier: string; | ||
|
||
name?: string; | ||
|
||
deleted?: boolean; | ||
|
||
createdAt: string; | ||
|
||
updatedAt: string; | ||
|
||
data?: TenantCustomData; | ||
|
||
_environmentId: EnvironmentId; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { CustomDataType } from '../shared'; | ||
|
||
export type TenantCustomData = CustomDataType; | ||
|
||
export type TenantId = string; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the
page
part to make sure it is straightforward.