Skip to content
13 changes: 12 additions & 1 deletion src/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -96,6 +102,11 @@ export class ApiClient {
responses,
}) as Promise<Letter>;
}

public async updateReviewer(reviewer: Reviewer): Promise<Reviewer> {
const { secondaryEmail, phone, reviewerUuid } = reviewer;
return this.patch(`/reviewer/${reviewerUuid}`, { secondaryEmail, phone }) as Promise<Reviewer>;
}
}

export default new ApiClient();
6 changes: 5 additions & 1 deletion src/api/dtos/survey-assignment.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions src/components/survey/CollectContactPage.tsx
Original file line number Diff line number Diff line change
@@ -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<CollectContactPageProps> = ({ confirm }) => (
const CollectContactPage: React.FC<CollectContactPageProps> = ({
reviewer,
reviewerUuid,
confirm,
}) => (
<Center mt={20}>
<VStack justify="center" height="full">
<Box padding="4" W="md">
<Text fontWeight={600} mb={6}>
Please provide additional contact information if you desire
</Text>
<ContactInfoCollect onSubmit={confirm} />
<ContactInfoCollect reviewer={reviewer} reviewerUuid={reviewerUuid} confirm={confirm} />
</Box>
</VStack>
</Center>
Expand Down
23 changes: 19 additions & 4 deletions src/components/survey/ContactInfoCollect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ 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;
phoneNumber: string;
}

interface ContactFormProps {
onSubmit: () => void;
reviewer: Reviewer;
reviewerUuid: string | undefined;
confirm: () => void;
}

const validateEmail = (value: string) => {
Expand All @@ -38,7 +42,7 @@ const validatePhoneNumber = (value: string) => {
return error;
};

const ContactInfoCollect: React.FC<ContactFormProps> = ({ onSubmit }) => {
const ContactInfoCollect: React.FC<ContactFormProps> = ({ reviewer, reviewerUuid, confirm }) => {
const [email, setEmail] = useState('');
const [phoneNumber, setPhoneNumber] = useState('');
const toast = useToast();
Expand Down Expand Up @@ -69,8 +73,19 @@ const ContactInfoCollect: React.FC<ContactFormProps> = ({ 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a handler for if this API call fails? If not, should there be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think there is a handler. @onb6 should i add a try catch that shows an alert if the api call failed.

confirm();
}
};

// eslint-disable-next-line no-alert
Expand Down
8 changes: 7 additions & 1 deletion src/components/survey/SurveyViewController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import CollectContactPage from './CollectContactPage';

interface SurveyViewControllerProps extends SurveyData {
completeAssignment: (assignmentUuid: string, responses: Response[]) => Promise<void>;
reviewerUuid: string | undefined;
}

/**
Expand All @@ -32,6 +33,7 @@ const SurveyViewController: React.FC<SurveyViewControllerProps> = ({
completeAssignment,
reviewer,
questions,
reviewerUuid,
}) => {
// See state machine visualization in `stateMachine.ts` for the entire state machine flow.
const [state, send] = useMachine(createSurveyViewMachine(treatmentYouth, controlYouth));
Expand Down Expand Up @@ -73,7 +75,11 @@ const SurveyViewController: React.FC<SurveyViewControllerProps> = ({
)}

{state.matches('provideContactInfo') && (
<CollectContactPage confirm={() => send('CONFIRM')} />
<CollectContactPage
reviewerUuid={reviewerUuid}
reviewer={reviewer}
confirm={() => send('CONFIRM')}
/>
)}

{state.matches('confirmAssignments') && (
Expand Down
1 change: 1 addition & 0 deletions src/pages/survey/SurveyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const SurveyPage: React.FC = () => {
{isLoading && <LoadingSpinner />}
{data && (
<SurveyViewController
reviewerUuid={reviewerUuid}
reviewer={data.reviewer}
questions={data.questions}
treatmentYouth={data.treatmentYouth}
Expand Down