-
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.
- Loading branch information
Showing
17 changed files
with
241 additions
and
130 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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
export enum Routes { | ||
export enum RoutePaths { | ||
Root = '/', | ||
UiKit = '/ui-kit', | ||
Profiles = '/profiles', | ||
// FIXME: how to avoid * in the path? | ||
Orgs = '/organisations/*', | ||
OrgNew = '/organisations/new', | ||
SignIn = '/sign-in', | ||
|
||
Orgs = '/organisations', | ||
OrgsList = '/organisations/list', | ||
OrgsListAll = '/organisations/list/all', | ||
OrgsListMy = '/organisations/list/my', | ||
OrgsNew = '/organisations/new', | ||
OrgsId = '/organisations/:id', | ||
OrgsIdCheckProof = '/organisations/:id/check-proof', | ||
} |
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,3 @@ | ||
export const createDeepPath = (path: string) => { | ||
return path.endsWith('*') ? path : `${path}/*` | ||
} |
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,15 @@ | ||
import { RouteObject, useRoutes } from 'react-router-dom' | ||
|
||
import { RoutePaths } from '@/enums' | ||
import { createDeepPath } from '@/helpers' | ||
|
||
// HACK: reqact-router v6 doesn't support absolute paths in the nested routes | ||
// Discussion: https://github.com/remix-run/react-router/discussions/9841 | ||
export const useNestedRoutes = (root: RoutePaths, routes: RouteObject[]) => { | ||
return useRoutes( | ||
routes.map(({ path, ...rest }) => ({ | ||
path: path && createDeepPath(path.replace(root, '')), | ||
...rest, | ||
})), | ||
) | ||
} |
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,106 +1,27 @@ | ||
import { Stack } from '@mui/material' | ||
import { useCallback, useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { Navigate, NavLink, Route, Routes } from 'react-router-dom' | ||
import { Navigate } from 'react-router-dom' | ||
|
||
import { loadOrgsAmount, OrgsRequestFilters, OrgsRequestFiltersMap } from '@/api' | ||
import { PageListFilters, PageTitles } from '@/common' | ||
import { Routes as RoutesPaths } from '@/enums' | ||
import { useLoading } from '@/hooks' | ||
import { UiButton, UiIcon, UiSwitch } from '@/ui' | ||
import { RoutePaths } from '@/enums' | ||
import { useNestedRoutes } from '@/hooks' | ||
|
||
import { List } from './components' | ||
|
||
enum OrgsRoutes { | ||
All = 'all', | ||
My = 'my', | ||
} | ||
import { OrgsId, OrgsList, OrgsNew } from './pages' | ||
|
||
export default function Orgs() { | ||
const { t } = useTranslation() | ||
|
||
const [filter, setFilter] = useState<OrgsRequestFiltersMap>({}) | ||
|
||
const init = useCallback(async () => { | ||
const { data } = await loadOrgsAmount() | ||
|
||
return data | ||
}, []) | ||
|
||
const { data: orgsAmount } = useLoading<number | undefined>(undefined, init, { | ||
loadOnMount: true, | ||
}) | ||
|
||
return ( | ||
<Stack flex={1} gap={6}> | ||
<PageTitles title={t('org-list.title')} subtitle={t('org-list.subtitle')} /> | ||
<PageListFilters | ||
tabs={[ | ||
{ | ||
label: `All${orgsAmount ? ` (${orgsAmount})` : ''}`, | ||
route: OrgsRoutes.All, | ||
}, | ||
{ | ||
label: 'My Organizations', | ||
route: OrgsRoutes.My, | ||
}, | ||
]} | ||
onSearchInput={(value: string) => | ||
setFilter(prev => ({ | ||
...prev, | ||
|
||
// FIXME: remove this and add searching orgs by name in backend | ||
[OrgsRequestFilters.UserDid]: value, | ||
})) | ||
} | ||
actionBar={ | ||
<Stack direction='row' gap={4} justifyContent='space-between'> | ||
<UiSwitch label='Show Only active' /> | ||
|
||
<NavLink to={RoutesPaths.OrgNew}> | ||
<UiButton | ||
variant='contained' | ||
color='primary' | ||
startIcon={<UiIcon componentName='add' />} | ||
> | ||
New Organization | ||
</UiButton> | ||
</NavLink> | ||
</Stack> | ||
} | ||
/> | ||
|
||
<Stack flex={1}> | ||
<Routes> | ||
<Route | ||
path={OrgsRoutes.All} | ||
element={ | ||
<List | ||
filter={{ | ||
...filter, | ||
}} | ||
/> | ||
} | ||
/> | ||
<Route | ||
path={OrgsRoutes.My} | ||
element={ | ||
<List | ||
filter={{ | ||
...filter, | ||
|
||
/** | ||
* FIXME: get userDid from {@link useMetamaskZkpSnapContext} | ||
*/ | ||
[OrgsRequestFilters.UserDid]: 'did:iden3:readonly:blabla', | ||
}} | ||
/> | ||
} | ||
/> | ||
|
||
<Route path='*' element={<Navigate replace to={OrgsRoutes.All} />} /> | ||
</Routes> | ||
</Stack> | ||
</Stack> | ||
) | ||
return useNestedRoutes(RoutePaths.Orgs, [ | ||
{ | ||
index: true, | ||
element: <Navigate replace to={RoutePaths.OrgsList} />, | ||
}, | ||
{ | ||
path: RoutePaths.OrgsList, | ||
element: <OrgsList />, | ||
}, | ||
{ | ||
path: RoutePaths.OrgsNew, | ||
element: <OrgsNew />, | ||
}, | ||
{ | ||
path: RoutePaths.OrgsId, | ||
element: <OrgsId />, | ||
}, | ||
]) | ||
} |
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,17 @@ | ||
import { RoutePaths } from '@/enums' | ||
import { useNestedRoutes } from '@/hooks' | ||
|
||
import { OrgCheckProof, OrgRoot } from './pages' | ||
|
||
export default function OrgsId() { | ||
return useNestedRoutes(RoutePaths.OrgsId, [ | ||
{ | ||
index: true, | ||
element: <OrgRoot />, | ||
}, | ||
{ | ||
path: RoutePaths.OrgsIdCheckProof, | ||
element: <OrgCheckProof />, | ||
}, | ||
]) | ||
} |
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,14 @@ | ||
import { Stack } from '@mui/material' | ||
import { useParams } from 'react-router-dom' | ||
|
||
import { PageTitles } from '@/common' | ||
|
||
export default function OrgCheckProof() { | ||
const { id } = useParams<{ id: string }>() | ||
|
||
return ( | ||
<Stack flex={1}> | ||
<PageTitles title={`OrgCheckProof ${id}`} subtitle='Some organization description' /> | ||
</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,22 @@ | ||
import { Box, Stack } from '@mui/material' | ||
import { generatePath, NavLink, useParams } from 'react-router-dom' | ||
|
||
import { PageTitles } from '@/common' | ||
import { RoutePaths } from '@/enums' | ||
import { UiButton } from '@/ui' | ||
|
||
export default function OrgRoot() { | ||
const { id = null } = useParams<{ id: string }>() | ||
|
||
return ( | ||
<Stack flex={1}> | ||
<PageTitles title={`Organization ${id}`} subtitle='Some organization description' /> | ||
|
||
<Box mt={6}> | ||
<NavLink to={generatePath(RoutePaths.OrgsIdCheckProof, { id })}> | ||
<UiButton component='div'>Check proof</UiButton> | ||
</NavLink> | ||
</Box> | ||
</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,2 @@ | ||
export { default as OrgCheckProof } from './OrgCheckProof' | ||
export { default as OrgRoot } from './OrgRoot' |
File renamed without changes.
File renamed without changes.
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,102 @@ | ||
import { Stack } from '@mui/material' | ||
import { useCallback, useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { Navigate, NavLink } from 'react-router-dom' | ||
|
||
import { loadOrgsAmount, OrgsRequestFilters, OrgsRequestFiltersMap } from '@/api' | ||
import { PageListFilters, PageTitles } from '@/common' | ||
import { RoutePaths } from '@/enums' | ||
import { useLoading, useNestedRoutes } from '@/hooks' | ||
import { UiButton, UiIcon, UiSwitch } from '@/ui' | ||
|
||
import { List } from './components' | ||
|
||
export default function OrgsList() { | ||
const { t } = useTranslation() | ||
|
||
const [filter, setFilter] = useState<OrgsRequestFiltersMap>({}) | ||
const routes = useNestedRoutes(RoutePaths.Orgs, [ | ||
{ | ||
index: true, | ||
element: <Navigate replace to={RoutePaths.OrgsListAll} />, | ||
}, | ||
{ | ||
path: RoutePaths.OrgsListAll, | ||
element: ( | ||
<List | ||
filter={{ | ||
...filter, | ||
}} | ||
/> | ||
), | ||
}, | ||
{ | ||
path: RoutePaths.OrgsListMy, | ||
element: ( | ||
<List | ||
filter={{ | ||
...filter, | ||
|
||
/** | ||
* FIXME: get userDid from {@link useMetamaskZkpSnapContext} | ||
*/ | ||
[OrgsRequestFilters.UserDid]: 'did:iden3:readonly:blabla', | ||
}} | ||
/> | ||
), | ||
}, | ||
]) | ||
|
||
const init = useCallback(async () => { | ||
const { data } = await loadOrgsAmount() | ||
|
||
return data | ||
}, []) | ||
|
||
const { data: orgsAmount } = useLoading<number | undefined>(undefined, init, { | ||
loadOnMount: true, | ||
}) | ||
|
||
return ( | ||
<Stack flex={1} gap={6}> | ||
<PageTitles title={t('org-list.title')} subtitle={t('org-list.subtitle')} /> | ||
<PageListFilters | ||
tabs={[ | ||
{ | ||
label: `All${orgsAmount ? ` (${orgsAmount})` : ''}`, | ||
route: RoutePaths.OrgsListAll, | ||
}, | ||
{ | ||
label: 'My Organizations', | ||
route: RoutePaths.OrgsListMy, | ||
}, | ||
]} | ||
onSearchInput={(value: string) => | ||
setFilter(prev => ({ | ||
...prev, | ||
|
||
// FIXME: remove this and add searching orgs by name in backend | ||
[OrgsRequestFilters.UserDid]: value, | ||
})) | ||
} | ||
actionBar={ | ||
<Stack direction='row' gap={4} justifyContent='space-between'> | ||
<UiSwitch label='Show Only active' /> | ||
|
||
<NavLink to={RoutePaths.OrgsNew}> | ||
<UiButton | ||
variant='contained' | ||
color='primary' | ||
startIcon={<UiIcon componentName='add' />} | ||
> | ||
New Organization | ||
</UiButton> | ||
</NavLink> | ||
</Stack> | ||
} | ||
/> | ||
|
||
<Stack flex={1}>{routes}</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,11 @@ | ||
import { Stack } from '@mui/material' | ||
|
||
import { PageTitles } from '@/common' | ||
|
||
export default function OrgsNew() { | ||
return ( | ||
<Stack flex={1}> | ||
<PageTitles title={'New organisation'} /> | ||
</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,3 @@ | ||
export { default as OrgsId } from './OrgsId' | ||
export { default as OrgsList } from './OrgsList' | ||
export { default as OrgsNew } from './OrgsNew' |
Oops, something went wrong.