diff --git a/src/api/apiClient.ts b/src/api/apiClient.ts index 25c47a4..185b639 100644 --- a/src/api/apiClient.ts +++ b/src/api/apiClient.ts @@ -2,7 +2,13 @@ import { Auth } from 'aws-amplify'; import axios, { AxiosInstance } from 'axios'; import { Letter } from './dtos/letter'; import Role from './dtos/role'; -import { Response, Survey, SurveyData, surveysSchema } from './dtos/survey-assignment.dto'; +import { + Response, + Reviewer, + Survey, + SurveyData, + surveysSchema, +} from './dtos/survey-assignment.dto'; import User from './dtos/user.dto'; const defaultBaseUrl = process.env.REACT_APP_API_BASE_URL ?? 'http://localhost:5000'; @@ -96,6 +102,11 @@ export class ApiClient { responses, }) as Promise; } + + public async updateReviewer(reviewer: Reviewer): Promise { + const { secondaryEmail, phone, reviewerUuid } = reviewer; + return this.patch(`/reviewer/${reviewerUuid}`, { secondaryEmail, phone }) as Promise; + } } export default new ApiClient(); diff --git a/src/api/dtos/survey-assignment.dto.ts b/src/api/dtos/survey-assignment.dto.ts index 7ef0c61..49b5305 100644 --- a/src/api/dtos/survey-assignment.dto.ts +++ b/src/api/dtos/survey-assignment.dto.ts @@ -42,7 +42,11 @@ export interface Youth extends PersonInfo { assignmentUuid: string; } -export type Reviewer = PersonInfo; +export interface Reviewer extends PersonInfo { + reviewerUuid: string; + secondaryEmail: string; + phone: string; +} interface PersonInfo { email: string; diff --git a/src/components/survey/CollectContactPage.tsx b/src/components/survey/CollectContactPage.tsx index ce9d1e3..bbf60b1 100644 --- a/src/components/survey/CollectContactPage.tsx +++ b/src/components/survey/CollectContactPage.tsx @@ -1,19 +1,26 @@ import React from 'react'; import { Box, Center, Text, VStack } from '@chakra-ui/react'; import ContactInfoCollect from './ContactInfoCollect'; +import { Reviewer } from '../../api/dtos/survey-assignment.dto'; interface CollectContactPageProps { + reviewer: Reviewer; + reviewerUuid: string | undefined; confirm: () => void; } -const CollectContactPage: React.FC = ({ confirm }) => ( +const CollectContactPage: React.FC = ({ + reviewer, + reviewerUuid, + confirm, +}) => (
Please provide additional contact information if you desire - +
diff --git a/src/components/survey/ContactInfoCollect.tsx b/src/components/survey/ContactInfoCollect.tsx index 35ed614..b9e4f33 100644 --- a/src/components/survey/ContactInfoCollect.tsx +++ b/src/components/survey/ContactInfoCollect.tsx @@ -10,6 +10,8 @@ import { VStack, } from '@chakra-ui/react'; import React, { useState } from 'react'; +import apiClient from '../../api/apiClient'; +import { Reviewer } from '../../api/dtos/survey-assignment.dto'; export interface ContactFormValues { email: string; @@ -17,7 +19,9 @@ export interface ContactFormValues { } interface ContactFormProps { - onSubmit: () => void; + reviewer: Reviewer; + reviewerUuid: string | undefined; + confirm: () => void; } const validateEmail = (value: string) => { @@ -38,7 +42,7 @@ const validatePhoneNumber = (value: string) => { return error; }; -const ContactInfoCollect: React.FC = ({ onSubmit }) => { +const ContactInfoCollect: React.FC = ({ reviewer, reviewerUuid, confirm }) => { const [email, setEmail] = useState(''); const [phoneNumber, setPhoneNumber] = useState(''); const toast = useToast(); @@ -69,8 +73,19 @@ const ContactInfoCollect: React.FC = ({ onSubmit }) => { }); return; } - // TODO: Send email and phone number to the backend - onSubmit(); + if (reviewerUuid) { + const updateReviewer = { + email: reviewer.email, + firstName: reviewer.firstName, + lastName: reviewer.lastName, + reviewerUuid, + secondaryEmail: email, + phone: phoneNumber, + }; + // TODO: Send email and phone number to the backend + await apiClient.updateReviewer(updateReviewer); + confirm(); + } }; // eslint-disable-next-line no-alert diff --git a/src/components/survey/SurveyViewController.tsx b/src/components/survey/SurveyViewController.tsx index f13ab32..a27862f 100644 --- a/src/components/survey/SurveyViewController.tsx +++ b/src/components/survey/SurveyViewController.tsx @@ -16,6 +16,7 @@ import CollectContactPage from './CollectContactPage'; interface SurveyViewControllerProps extends SurveyData { completeAssignment: (assignmentUuid: string, responses: Response[]) => Promise; + reviewerUuid: string | undefined; } /** @@ -32,6 +33,7 @@ const SurveyViewController: React.FC = ({ completeAssignment, reviewer, questions, + reviewerUuid, }) => { // See state machine visualization in `stateMachine.ts` for the entire state machine flow. const [state, send] = useMachine(createSurveyViewMachine(treatmentYouth, controlYouth)); @@ -73,7 +75,11 @@ const SurveyViewController: React.FC = ({ )} {state.matches('provideContactInfo') && ( - send('CONFIRM')} /> + send('CONFIRM')} + /> )} {state.matches('confirmAssignments') && ( diff --git a/src/pages/survey/SurveyPage.tsx b/src/pages/survey/SurveyPage.tsx index 0c07794..dbbb962 100644 --- a/src/pages/survey/SurveyPage.tsx +++ b/src/pages/survey/SurveyPage.tsx @@ -39,6 +39,7 @@ const SurveyPage: React.FC = () => { {isLoading && } {data && (