-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2552 from bcgov/DESENG-642-survey-data-router-fea…
…tures [To Main] DESENG-642: Survey data router features
- Loading branch information
Showing
37 changed files
with
1,003 additions
and
1,322 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
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
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
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
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
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,33 @@ | ||
import { Params, defer } from 'react-router-dom'; | ||
import { getEmailVerification } from 'services/emailVerificationService'; | ||
import { getEngagement } from 'services/engagementService'; | ||
import { getEngagementIdBySlug, getSlugByEngagementId } from 'services/engagementSlugService'; | ||
import { getSubmissionByToken } from 'services/submissionService'; | ||
import { getSurvey } from 'services/surveyService'; | ||
import { fetchSurveyReportSettings } from 'services/surveyService/reportSettingsService'; | ||
|
||
export const SurveyLoader = async ({ params }: { params: Params<string> }) => { | ||
const { surveyId, token, language, engagementId, slug: urlSlug } = params; | ||
if (isNaN(Number(surveyId)) && !isNaN(Number(engagementId)) && !urlSlug) throw new Error('Invalid survey ID'); | ||
const verification = getEmailVerification(token ?? '').catch(() => null); | ||
const getSurveyPromise = () => { | ||
if (!isNaN(Number(surveyId))) return getSurvey(Number(surveyId)); | ||
if (urlSlug) | ||
return getEngagementIdBySlug(urlSlug ?? '').then((response) => | ||
getEngagement(response.engagement_id).then((response) => Promise.resolve(response.surveys[0])), | ||
); | ||
return getEngagement(Number(engagementId)).then((response) => Promise.resolve(response.surveys[0])); | ||
}; | ||
const survey = getSurveyPromise(); | ||
|
||
const submission = verification.then( | ||
(response) => response && getSubmissionByToken(response?.verification_token ?? ''), | ||
); | ||
const reportSettings = survey.then((response) => fetchSurveyReportSettings(response.id.toString())); | ||
const engagement = survey.then((response) => { | ||
if (!response.engagement_id) return null; | ||
return getEngagement(response.engagement_id); | ||
}); | ||
const slug = engagement.then((response) => response && getSlugByEngagementId(response.id)); | ||
return defer({ engagement, language, reportSettings, slug, submission, survey, surveyId, token, verification }); | ||
}; |
Oops, something went wrong.