File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { Form } from '@douglasneuroinformatics/libui/components' ;
2+ import { useTranslation } from '@douglasneuroinformatics/libui/hooks' ;
3+ import type { SetupState , UpdateSetupStateData } from '@opendatacapture/schemas/setup' ;
4+ import type { Promisable , SetNonNullable } from 'type-fest' ;
5+ import { z } from 'zod' ;
6+
7+ export type AppSettingsFormProps = {
8+ initialValues : SetupState ;
9+ onSubmit : ( data : UpdateSetupStateData ) => Promisable < any > ;
10+ } ;
11+
12+ export const AppSettingsForm = ( { initialValues, onSubmit } : AppSettingsFormProps ) => {
13+ const { t } = useTranslation ( ) ;
14+ return (
15+ < Form
16+ className = "mx-auto max-w-3xl"
17+ content = { {
18+ isExperimentalFeaturesEnabled : {
19+ kind : 'boolean' ,
20+ label : t ( 'setup.enableExperimentalFeatures' ) ,
21+ variant : 'radio'
22+ }
23+ } }
24+ initialValues = { initialValues }
25+ preventResetValuesOnReset = { true }
26+ validationSchema = {
27+ z . object ( {
28+ isExperimentalFeaturesEnabled : z . boolean ( )
29+ } ) satisfies z . ZodType < SetNonNullable < UpdateSetupStateData > >
30+ }
31+ onSubmit = { ( data ) => void onSubmit ( data ) }
32+ />
33+ ) ;
34+ } ;
Original file line number Diff line number Diff line change 1+ import { useNotificationsStore } from '@douglasneuroinformatics/libui/hooks' ;
2+ import type { UpdateSetupStateData } from '@opendatacapture/schemas/setup' ;
3+ import { useMutation } from '@tanstack/react-query' ;
4+ import axios from 'axios' ;
5+
6+ export function useUpdateSetupStateMutation ( ) {
7+ const addNotification = useNotificationsStore ( ( store ) => store . addNotification ) ;
8+ return useMutation ( {
9+ mutationFn : async ( data : UpdateSetupStateData ) => {
10+ await axios . patch ( '/v1/setup' , data ) ;
11+ } ,
12+ onSuccess ( ) {
13+ addNotification ( { type : 'success' } ) ;
14+ }
15+ } ) ;
16+ }
Original file line number Diff line number Diff line change 22
33import type { RouteObject } from 'react-router-dom' ;
44
5- import { AdminSettingsPage } from './pages/AdminSettingsPage ' ;
5+ import { AppSettingsPage } from './pages/AppSettingsPage ' ;
66import { CreateGroupPage } from './pages/CreateGroupPage' ;
77import { CreateUserPage } from './pages/CreateUserPage' ;
88import { ManageGroupsPage } from './pages/ManageGroupsPage' ;
@@ -39,7 +39,7 @@ export const adminRoute: RouteObject = {
3939 } ,
4040 {
4141 path : 'settings' ,
42- element : < AdminSettingsPage />
42+ element : < AppSettingsPage />
4343 }
4444 ]
4545} ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+
3+ import { Heading } from '@douglasneuroinformatics/libui/components' ;
4+ import { useTranslation } from '@douglasneuroinformatics/libui/hooks' ;
5+ import type { UpdateSetupStateData } from '@opendatacapture/schemas/setup' ;
6+
7+ import { PageHeader } from '@/components/PageHeader' ;
8+ import { useSetupState } from '@/hooks/useSetupState' ;
9+
10+ import { AppSettingsForm } from '../components/AppSettingsForm' ;
11+ import { useUpdateSetupStateMutation } from '../hooks/useUpdateSetupStateMutation' ;
12+
13+ export const AppSettingsPage = ( ) => {
14+ const { t } = useTranslation ( ) ;
15+ const setupState = useSetupState ( ) ;
16+ const updateSetupStateMutation = useUpdateSetupStateMutation ( ) ;
17+
18+ const handleSubmit = ( data : UpdateSetupStateData ) => {
19+ updateSetupStateMutation . mutate ( data ) ;
20+ } ;
21+
22+ return (
23+ < React . Fragment >
24+ < PageHeader >
25+ < Heading className = "text-center" variant = "h2" >
26+ { t ( {
27+ en : 'Modify Application Settings' ,
28+ fr : "Modifier les paramètres de l'application"
29+ } ) }
30+ </ Heading >
31+ </ PageHeader >
32+ { setupState . data && < AppSettingsForm initialValues = { setupState . data } onSubmit = { handleSubmit } /> }
33+ </ React . Fragment >
34+ ) ;
35+ } ;
Original file line number Diff line number Diff line change @@ -68,10 +68,7 @@ export const SetupPage = ({ onSubmit }: SetupPageProps) => {
6868 fields : {
6969 enableExperimentalFeatures : {
7070 kind : 'boolean' ,
71- label : t ( {
72- en : 'Enable Experimental Features' ,
73- fr : 'Activer les fonctionnalités expérimentales'
74- } ) ,
71+ label : t ( 'setup.enableExperimentalFeatures' ) ,
7572 variant : 'radio'
7673 } ,
7774 initDemo : {
@@ -116,6 +113,9 @@ export const SetupPage = ({ onSubmit }: SetupPageProps) => {
116113 }
117114 ] }
118115 data-cy = "setup-form"
116+ initialValues = { {
117+ enableExperimentalFeatures : false
118+ } }
119119 submitBtnLabel = { t ( 'core.submit' ) }
120120 validationSchema = { z . object ( {
121121 firstName : z . string ( ) . min ( 1 ) ,
Original file line number Diff line number Diff line change 3939 "fr" : " Démonstration"
4040 }
4141 },
42+ "enableExperimentalFeatures" : {
43+ "en" : " Enable Experimental Features (Not Recommended)" ,
44+ "fr" : " Activer les fonctionnalités expérimentales (Non recommandé)"
45+ },
4246 "loadingSubtitle" : {
4347 "en" : " Please be patient, this may take a while..." ,
4448 "fr" : " Veuillez patienter, cela peut prendre un certain temps..."
You can’t perform that action at this time.
0 commit comments