@@ -5,23 +5,15 @@ import {
55 BreadCrumbs ,
66} from '@app-builder/components/Breadcrumbs' ;
77import { Nudge } from '@app-builder/components/Nudge' ;
8- import { type CurrentUser , isAdmin } from '@app-builder/models' ;
9- import { type Inbox } from '@app-builder/models/inbox' ;
10- import {
11- canAccessInboxesSettings ,
12- isAccessible ,
13- isReadApiKeyAvailable ,
14- isReadTagAvailable ,
15- isReadUserAvailable ,
16- } from '@app-builder/services/feature-access' ;
8+ import { isAccessible } from '@app-builder/services/feature-access' ;
179import { initServerServices } from '@app-builder/services/init.server' ;
10+ import { getSettingsAccess } from '@app-builder/services/settings-access' ;
1811import { getRoute } from '@app-builder/utils/routes' ;
1912import { type LoaderFunctionArgs } from '@remix-run/node' ;
2013import { NavLink , Outlet , useLoaderData } from '@remix-run/react' ;
2114import clsx from 'clsx' ;
2215import { type Namespace } from 'i18next' ;
2316import { useTranslation } from 'react-i18next' ;
24- import * as R from 'remeda' ;
2517import { Icon } from 'ui-icons' ;
2618
2719export const handle = {
@@ -40,81 +32,15 @@ export const handle = {
4032 ] ,
4133} ;
4234
43- export function getSettings ( user : CurrentUser , inboxes : Inbox [ ] ) {
44- const settings = [ ] ;
45- if ( isReadUserAvailable ( user ) ) {
46- settings . push ( {
47- section : 'users' as const ,
48- title : 'users' as const ,
49- to : getRoute ( '/settings/users' ) ,
50- } ) ;
51- }
52- if ( isAdmin ( user ) ) {
53- settings . push ( {
54- section : 'scenarios' as const ,
55- title : 'scenarios' as const ,
56- to : getRoute ( '/settings/scenarios' ) ,
57- } ) ;
58- }
59- if ( canAccessInboxesSettings ( user , inboxes ) ) {
60- settings . push ( {
61- section : 'case_manager' as const ,
62- title : 'inboxes' as const ,
63- to : getRoute ( '/settings/inboxes' ) ,
64- } ) ;
65- }
66- if ( isReadTagAvailable ( user ) ) {
67- settings . push ( {
68- section : 'case_manager' as const ,
69- title : 'tags' as const ,
70- to : getRoute ( '/settings/tags' ) ,
71- } ) ;
72- }
73- if ( isReadApiKeyAvailable ( user ) ) {
74- settings . push ( {
75- section : 'api' as const ,
76- title : 'api' as const ,
77- to : getRoute ( '/settings/api-keys' ) ,
78- } ) ;
79- }
80- if ( user . permissions . canManageWebhooks ) {
81- settings . push ( {
82- section : 'api' as const ,
83- title : 'webhooks' as const ,
84- to : getRoute ( '/settings/webhooks' ) ,
85- } ) ;
86- }
87- if ( isAdmin ( user ) ) {
88- settings . push (
89- {
90- section : 'case_manager' as const ,
91- title : 'ia_case_review' as const ,
92- to : getRoute ( '/settings/ia-case-review' ) ,
93- } ,
94- {
95- section : 'case_manager' as const ,
96- title : 'data_display' as const ,
97- to : getRoute ( '/settings/data-display' ) ,
98- } ,
99- ) ;
100- }
101- return settings ;
102- }
103-
10435export async function loader ( { request } : LoaderFunctionArgs ) {
10536 const { authService } = initServerServices ( request ) ;
10637 const { user, entitlements, inbox } = await authService . isAuthenticated ( request , {
10738 failureRedirect : getRoute ( '/sign-in' ) ,
10839 } ) ;
10940
11041 const inboxes = await inbox . listInboxes ( ) ;
111- const settings = getSettings ( user , inboxes ) ;
11242
113- const sections = R . pipe (
114- settings ,
115- R . groupBy ( ( s ) => s . section ) ,
116- R . entries ( ) ,
117- ) ;
43+ const sections = getSettingsAccess ( user , inboxes ) ;
11844
11945 return { sections, entitlements } ;
12046}
@@ -131,21 +57,18 @@ export default function Settings() {
13157 < div className = "flex size-full flex-row overflow-hidden" >
13258 < div className = "border-e-grey-90 bg-grey-100 flex h-full w-fit min-w-[200px] flex-col overflow-y-auto border-e p-4" >
13359 < div className = "flex flex-col" >
134- { sections . map ( ( [ section , settings ] ) => {
60+ { Object . entries ( sections ) . map ( ( [ section , { icon, settings } ] ) => {
61+ console . log ( 'section' ) ;
62+ console . log ( section ) ;
63+ console . log ( 'settings' ) ;
64+ console . log ( settings ) ;
13565 if ( settings . length === 0 ) return null ;
13666
137- const icon =
138- section === 'users'
139- ? 'users'
140- : section === 'case_manager'
141- ? 'case-manager'
142- : 'world' ;
143-
14467 return (
14568 < nav key = { section } className = "flex flex-col gap-4" >
14669 < div className = "flex flex-row items-center gap-2" >
14770 < Icon icon = { icon } className = "size-5" />
148- < p className = "font-bold" > { t ( `settings:${ section } ` ) } </ p >
71+ < p className = "font-bold" > { t ( `settings:${ section } ` as any ) } </ p >
14972 </ div >
15073 < ul className = "flex flex-col gap-1 pb-6" >
15174 { settings . map ( ( setting ) =>
@@ -154,7 +77,7 @@ export default function Settings() {
15477 key = { setting . title }
15578 className = "text-s bg-grey-100 text-grey-80 inline-flex w-full gap-2 p-2 font-medium first-letter:capitalize"
15679 >
157- { t ( `settings:${ setting . title } ` ) }
80+ { t ( `settings:${ setting . title } ` as any ) }
15881 { entitlements . webhooks !== 'allowed' ? (
15982 < Nudge content = "" kind = "restricted" className = "size-5" />
16083 ) : null }
@@ -172,7 +95,7 @@ export default function Settings() {
17295 }
17396 to = { setting . to }
17497 >
175- { t ( `settings:${ setting . title } ` ) }
98+ { t ( `settings:${ setting . title } ` as any ) }
17699 </ NavLink >
177100 ) ,
178101 ) }
0 commit comments