Skip to content

Commit

Permalink
wip surveyUnitId route
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Jan 12, 2024
1 parent e483d19 commit 3edbdb9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
2 changes: 2 additions & 0 deletions drama-queen/src/core/usecases/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as userAuthentication from './userAuthentication'
import * as synchronizeData from './synchronizeData'
import * as visualizeSurvey from './visualizeSurvey/visualizeSurvey'
import * as surveyUnit from './surveyUnit'
export const usecases = {
userAuthentication,
synchronizeData,
visualizeSurvey,
surveyUnit,
}
18 changes: 18 additions & 0 deletions drama-queen/src/core/usecases/surveyUnit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { assert } from 'tsafe/assert'
import type { Thunks } from 'core/bootstrap'

export const name = 'surveyUnit'

export const reducer = null

export const thunks = {
getSurveyWithSurveyUnit:
(params: { surveyUnitId: string }) =>
async (...args) => {
const [, , { dataStore }] = args
const { surveyUnitId } = params

const surveyUnit = await dataStore.getSurveyUnit(surveyUnitId)
return surveyUnit?.questionnaireId
},
} satisfies Thunks
5 changes: 5 additions & 0 deletions drama-queen/src/ui/pages/queenMapping/SurveyUnitMapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ type Params = {
}

export function SurveyUnitMapping() {
// When this component is displayed this means that there is an Error
/**
* I proposed to delete this component in order to make a generic error route, and that loader pass messageError directly
*/

const { readonly, id } = useParams<Params>()

return <div>Survey Unit Mapping id : {id}</div>
Expand Down
21 changes: 21 additions & 0 deletions drama-queen/src/ui/routing/loader/surveyUnitLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { prCore } from 'bootstrap'
import { redirect, type LoaderFunctionArgs } from 'react-router-dom'
import { assert } from 'tsafe'

export async function surveyUnitLoader({ params }: LoaderFunctionArgs) {
const { surveyUnit } = (await prCore).functions

const surveyUnitId = params.surveyUnitId

//surveyUnitId can't be undefined here (needed to match route)
assert(surveyUnitId !== undefined)

const questionnaireId = await surveyUnit.getSurveyWithSurveyUnit({
surveyUnitId,
})

//TODO handle case when questionnaireId is undefined
return redirect(
`/questionnaire/${questionnaireId}/survey-unit/${surveyUnitId}`
)
}
6 changes: 4 additions & 2 deletions drama-queen/src/ui/routing/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { Visualize } from 'ui/pages/visualize/Visualize'
import { Orchestrator } from 'ui/components/orchestrator/Orchestrator'
import { protectedRouteLoader } from './loader/protectedLoader'
import { visualizeLoader } from './loader/visualizeLoader'
import { surveyUnitLoader } from './loader/surveyUnitLoader'

//ReadOnly path is a bad pattern must be change (affects pearl,moog,queen)
export const routes: RouteObject[] = [
{
path: `/:${READ_ONLY}?/survey-unit/:id`,
element: <SurveyUnitMapping />,
path: '/survey-unit/:surveyUnitId',
Component: SurveyUnitMapping,
loader: surveyUnitLoader
},
{
path: `/:${READ_ONLY}?/questionnaire/:questionnaireId/survey-unit/:surveyUnitId`,
Expand Down

0 comments on commit 3edbdb9

Please sign in to comment.