-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add org list and create page structure wip * renames wip * add orgs api module * update imports * fix after review #4 * add small orgs loading example * refactored toasts manager * hotfix * hotfix * refactored navtabs * update orgs routes for orgs page
- Loading branch information
Showing
34 changed files
with
665 additions
and
132 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
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,6 @@ | ||
import { config } from '@config' | ||
import { JsonApiClient } from '@distributedlab/jac' | ||
|
||
export const api = new JsonApiClient({ | ||
baseUrl: config.API_URL, | ||
}) |
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,2 @@ | ||
export * from './clients' | ||
export * from './modules' |
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 './orgs' |
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,15 @@ | ||
export enum OrgsStatuses { | ||
Unverified = '0', | ||
Verified = '1', | ||
} | ||
|
||
export enum OrgsRequestFilters { | ||
Owner = 'owner', | ||
UserDid = 'user_did', | ||
Status = 'status', | ||
} | ||
|
||
export enum OrgsIncludes { | ||
organization = 'organization', | ||
owner = 'owner', | ||
} |
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,54 @@ | ||
import { | ||
api, | ||
type Organization, | ||
type OrganizationCreate, | ||
type OrgsRequestQueryParams, | ||
type OrgUser, | ||
type OrgVerificationCode, | ||
} from '@/api' | ||
|
||
export const loadOrgs = async (query: OrgsRequestQueryParams) => { | ||
return api.get<Organization[]>('/v1/orgs', { | ||
query, | ||
}) | ||
} | ||
|
||
export const loadOrgsAmount = async () => { | ||
return api.get<number>('/v1/orgs/amount') | ||
} | ||
|
||
export const loadOrgById = async (id: string, query: OrgsRequestQueryParams) => { | ||
return api.get<Organization>(`/v1/orgs/${id}`, { | ||
query, | ||
}) | ||
} | ||
|
||
export const createOrg = async (body: OrganizationCreate) => { | ||
return api.post<Organization>('/v1/orgs', { | ||
body: { | ||
data: { | ||
id: body.id, | ||
type: 'organizations-create', | ||
attributes: { | ||
owner_did: body.ownerDid, | ||
domain: body.domain, | ||
metadata: body.metadata, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
export const verifyOrg = async (id: string) => { | ||
return api.post<Organization>(`/v1/orgs/${id}`) | ||
} | ||
|
||
export const loadOrgUsers = async (id: string, query: OrgsRequestQueryParams) => { | ||
return api.get<OrgUser[]>(`/v1/orgs/${id}/users`, { | ||
query, | ||
}) | ||
} | ||
|
||
export const getOrgVerificationCode = async (id: string) => { | ||
return api.get<OrgVerificationCode>(`/v1/orgs/${id}/verification-code`) | ||
} |
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,3 @@ | ||
export * from './enums' | ||
export * from './helpers' | ||
export * from './types' |
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,62 @@ | ||
import type { OrgsIncludes, OrgsRequestFilters, OrgsStatuses } from '@/api' | ||
|
||
export type OrgMetadata = { | ||
name: string | ||
description: string | ||
} | ||
|
||
export type OrgUser = { | ||
id: string | ||
type: 'users' | ||
did: string | ||
role: { | ||
name: string | ||
value: number | ||
} | ||
org_id: string | ||
created_at: string | ||
updated_at: string | ||
} | ||
|
||
export type Organization = { | ||
id: string | ||
type: 'organizations' | ||
did: string | ||
owner?: OrgUser | ||
domain: string | ||
metadata: OrgMetadata | ||
status: { | ||
name: string | ||
value: OrgsStatuses | ||
} | ||
verification_code: string | ||
issued_claims_count: string | ||
members_count: string | ||
created_at: string | ||
updated_at: string | ||
} | ||
|
||
export type OrganizationCreate = { | ||
id: string | ||
ownerDid: string | ||
domain: string | ||
metadata: OrgMetadata | ||
} | ||
|
||
export type OrgsRequestFiltersMap = { | ||
[OrgsRequestFilters.Owner]?: string | ||
[OrgsRequestFilters.UserDid]?: string | ||
[OrgsRequestFilters.Status]?: OrgsStatuses | ||
} | ||
|
||
export type OrgsRequestQueryParams = { | ||
include?: OrgsIncludes | ||
filter?: OrgsRequestFiltersMap | ||
// TODO: page, limit, sort, ...etc | ||
} | ||
|
||
export type OrgVerificationCode = { | ||
id: string | ||
type: string | ||
code: string | ||
} |
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,66 @@ | ||
import { config } from '@config' | ||
import { ButtonProps, Divider, Stack } from '@mui/material' | ||
import { ReactNode, useMemo } from 'react' | ||
import { NavLink, useLocation } from 'react-router-dom' | ||
|
||
import { Icons, Routes } from '@/enums' | ||
import { UiButton, UiIcon } from '@/ui' | ||
|
||
interface NavbarLinkProps { | ||
to: Routes | ||
children: ReactNode | ||
} | ||
|
||
const NavbarLink = ({ children, to }: NavbarLinkProps) => { | ||
const location = useLocation() | ||
|
||
const linkProps = useMemo((): Partial<ButtonProps> => { | ||
const locationRoot = location.pathname.split('/')[1] | ||
|
||
const isRouteActive = to.includes(locationRoot) | ||
|
||
return { | ||
variant: isRouteActive ? 'contained' : 'text', | ||
color: isRouteActive ? 'primary' : 'secondary', | ||
} | ||
}, [location.pathname, to]) | ||
|
||
return ( | ||
<NavLink to={to}> | ||
<UiButton component='div' sx={{ p: 3 }} {...linkProps}> | ||
{children} | ||
</UiButton> | ||
</NavLink> | ||
) | ||
} | ||
|
||
const AppNavbar = () => { | ||
const navbarItems = useMemo( | ||
() => [ | ||
{ route: Routes.Profiles, iconComponent: <UiIcon name={Icons.Wallet} size={6} /> }, | ||
{ route: Routes.Orgs, iconComponent: <UiIcon componentName='work' size={6} /> }, | ||
], | ||
[], | ||
) | ||
|
||
return ( | ||
<Stack spacing={4} py={1}> | ||
<NavLink to={Routes.Profiles}> | ||
<Stack alignItems='center'> | ||
<img src='/branding/logo.svg' alt={config.APP_NAME} /> | ||
</Stack> | ||
</NavLink> | ||
<Divider /> | ||
|
||
<Stack py={6} gap={6}> | ||
{navbarItems.map(({ route, iconComponent }, idx) => ( | ||
<NavbarLink to={route} key={idx}> | ||
{iconComponent} | ||
</NavbarLink> | ||
))} | ||
</Stack> | ||
</Stack> | ||
) | ||
} | ||
|
||
export default AppNavbar |
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,41 @@ | ||
import { InputAdornment, Stack, StackProps } from '@mui/material' | ||
import debounce from 'lodash/debounce' | ||
import type { ReactNode } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { UiIcon, UiNavTabs, UiTextField } from '@/ui' | ||
|
||
interface Props extends StackProps { | ||
tabs?: { | ||
label: string | ||
route: string | ||
}[] | ||
onSearchInput?: (value: string) => void | ||
actionBar?: ReactNode | ||
} | ||
|
||
export default function PageListFilters({ tabs, onSearchInput, actionBar, ...rest }: Props) { | ||
const { t } = useTranslation() | ||
|
||
const handleSearchInput = debounce((value: string) => onSearchInput?.(value), 500) | ||
|
||
return ( | ||
<Stack {...rest} direction='row' alignItems='center' gap={5}> | ||
{tabs && <UiNavTabs tabs={tabs} />} | ||
|
||
<UiTextField | ||
InputProps={{ | ||
startAdornment: ( | ||
<InputAdornment position='start'> | ||
<UiIcon componentName='search' /> | ||
</InputAdornment> | ||
), | ||
}} | ||
placeholder={t('page-list-filters.search-input-placeholder')} | ||
onChange={e => handleSearchInput(e.target.value)} | ||
/> | ||
|
||
<Stack flex={1}>{actionBar}</Stack> | ||
</Stack> | ||
) | ||
} |
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,23 @@ | ||
import { Box, BoxProps, Divider, Typography } from '@mui/material' | ||
|
||
interface Props extends BoxProps { | ||
title: string | ||
subtitle?: string | ||
} | ||
|
||
export default function PageTitles({ title, subtitle, ...rest }: Props) { | ||
return ( | ||
<Box {...rest}> | ||
<Typography variant='h5' mb={2}> | ||
{title} | ||
</Typography> | ||
<Typography variant='body2'>{subtitle}</Typography> | ||
|
||
<Divider | ||
sx={theme => ({ | ||
mt: theme.spacing(6), | ||
})} | ||
/> | ||
</Box> | ||
) | ||
} |
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,3 @@ | ||
export { default as AppNavbar } from './AppNavbar' | ||
export { default as PageListFilters } from './PageListFilters' | ||
export { default as PageTitles } from './PageTitles' |
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
Oops, something went wrong.