diff --git a/client/src/hooks/useApi.tsx b/client/src/hooks/useApi.tsx index 4ef6ddb..4dee5cd 100644 --- a/client/src/hooks/useApi.tsx +++ b/client/src/hooks/useApi.tsx @@ -352,38 +352,47 @@ export const useApi = () => { type SurveyWithUser = SurveyDocument & { employeeName: string; employeeId: string; + locationName: string; }; const useSurveyWithUser = ( - surveyObjectId: string - ): SWRResponse => { + surveyObjectId: string | undefined + ): SWRResponse => { return useSWR( surveyObjectId ? `/api/surveys/${surveyObjectId}` : null, - () => fetchSurveyWithUser(surveyObjectId) + () => fetchSurveyWithUser(surveyObjectId!) ); }; const fetchSurveyWithUser = async ( surveyObjectId: string - ): Promise => { + ): Promise => { const survey = await fetchAndDeserialize( `/api/surveys/${surveyObjectId}` ); if (!survey) { - throw new Error( - 'Survey not found or you do not have permission to view it' - ); + return null; } - const user = await fetchAndDeserialize( - `/api/users/${survey.createdByUserObjectId}` - ); + + // Fetch user and location in parallel for efficiency + const [user, location] = await Promise.all([ + fetchAndDeserialize( + `/api/users/${survey.createdByUserObjectId}` + ), + survey.locationObjectId + ? fetchAndDeserialize( + `/api/locations/${survey.locationObjectId}` + ) + : Promise.resolve(null) + ]); return { ...survey, employeeName: user ? `${user.firstName} ${user.lastName}` : 'Unknown', - employeeId: user?._id ?? 'Unknown' + employeeId: user?._id ?? 'Unknown', + locationName: location?.hubName ?? 'Unknown' }; }; diff --git a/client/src/pages/Survey/utils/surveyUtils.tsx b/client/src/pages/Survey/utils/surveyUtils.tsx index 85db749..5f0618e 100644 --- a/client/src/pages/Survey/utils/surveyUtils.tsx +++ b/client/src/pages/Survey/utils/surveyUtils.tsx @@ -18,7 +18,13 @@ export const initializeSurvey = ( if (isEditMode) { // Edit mode only uses first 3 pages: volunteer-pre-screen, consent, survey-validation surveyJson.title = 'Homelessness Experience Survey (Edit Mode)'; - surveyJson.pages = surveyJson.pages.slice(0, 3); + // surveyJson.pages = surveyJson.pages.slice(0, 4); + surveyJson.pages = [ + ...surveyJson.pages.slice(0, 4), + surveyJson.pages[16], + surveyJson.pages[17] + ].filter(page => page !== undefined); + // Remove any early stop triggers to allow full editing of survey // Without this, the survey will stop early if consent is revoked, not allowing any edits to consecutive pages if (surveyJson.triggers) { diff --git a/client/src/pages/SurveyDetails/SurveyDetails.tsx b/client/src/pages/SurveyDetails/SurveyDetails.tsx index 95276a7..012a8ce 100644 --- a/client/src/pages/SurveyDetails/SurveyDetails.tsx +++ b/client/src/pages/SurveyDetails/SurveyDetails.tsx @@ -19,9 +19,9 @@ export default function SurveyDetails() { const { surveyService } = useApi(); const { data: survey, - isLoading: loading, - error - } = surveyService.useSurveyWithUser(id ?? '') || {}; + isLoading: loading + } = surveyService.useSurveyWithUser(id) || {}; + const error = !loading && !survey; const navigate = useNavigate(); const qrRefs = useRef<(HTMLDivElement | null)[]>([]); const ability = useAbility(); @@ -33,40 +33,23 @@ export default function SurveyDetails() { const canEdit = survey ? ability.can(ACTIONS.CASL.UPDATE, subject(SUBJECTS.SURVEY, survey)) : false; + // Fields to display in survey responses section + const displayFields = [ + 'first_two_letters_fname', + 'first_two_letters_lname', + 'date_of_birth', + 'email_phone_consent', + 'email', + 'phone' + ]; + const labelMap: Record = { - first_two_letters_fname: 'First two letters of first name', - first_two_letters_lname: 'First two letters of last name', - year_born: 'Year born', - month_born: 'Month born', - location: 'Location', - interpreter: 'Using interpreter?', - language: 'Language (if using interpreter)', - phone_number: 'Phone number', + first_two_letters_fname: 'First name initials', + first_two_letters_lname: 'Last name initials', + date_of_birth: 'Date of Birth', + email_phone_consent: 'Email/Phone Consent', email: 'Email', - email_consent: 'Consent to email', - age_for_consent: 'Age 18 or over?', - consent_given: 'Oral consent given?', - homeless_people_count: - 'Number of people experiencing homelessness you know', - people_you_know: 'People you know experiencing homelessness', - sleeping_location_last_night: 'Sleeping Location Last Night', - homeless_duration_since_housing: 'Homeless Duration Since Housing', - homeless_occurrences_past_3_years: 'Homeless Occurrences Past 3 Years', - months_homeless: 'Months Homeless', - age: 'Age', - hispanic_latino: 'Hispanic/Latino', - veteran: 'Veteran', - fleeing_dv: 'Fleeing Domestic Violence', - disability: 'Disability', - mental_illness: 'Mental Illness', - substance_abuse: 'Substance Abuse', - city_lasthoused: 'City Last Housed', - minutes_traveled: 'Minutes Traveled', - events_conditions: 'Events/Conditions', - shelter_preferences: 'Shelter Preferences', - person_name: 'Name', - relationship: 'Relationship', - current_sleeping_location: 'Current Sleeping Location' + phone: 'Phone' }; if (loading) return

Loading...

; @@ -119,17 +102,53 @@ export default function SurveyDetails() {

- Employee ID: {survey.employeeId} + Survey Code: {survey.surveyCode} +

+

+ Staff Name: {survey.employeeName}

- Employee Name: {survey.employeeName} + Location: {survey.locationName}

- Submitted At:{' '} + Date and Time:{' '} {new Date(survey.createdAt).toLocaleString()}

+ {/* Gift Card Information */} +
+

Gift Card Information

+
+						{survey.responses &&
+							displayFields
+								.filter(field => field in survey.responses)
+								.map(field => {
+									const answer = survey.responses[field];
+									const label = labelMap[field] || field;
+									return `${label}: ${answer ?? 'N/A'}`;
+								})
+								.join('\n\n')}
+					
+
+ {/* Edit Pre-screen Questions Button */} + + + + + {/* Coupon Code Information */}

Referral Information

@@ -198,62 +217,6 @@ export default function SurveyDetails() {
- - {/* Survey Responses */} -
-

Survey Responses

-
-						{survey.responses &&
-							Object.entries(survey.responses)
-								.map(([question, answer]) => {
-									const label =
-										labelMap[question] || question;
-
-									if (
-										question === 'people_you_know' &&
-										Array.isArray(answer)
-									) {
-										return (
-											`\n${label}:\n` +
-											answer
-												.map((person, index) => {
-													return (
-														`  Person ${index + 1}:\n` +
-														Object.entries(person)
-															.map(
-																([key, val]) =>
-																	`    ${key}: ${val}`
-															)
-															.join('\n')
-													);
-												})
-												.join('\n\n')
-										);
-									} else {
-										return `${label}: ${answer}`;
-									}
-								})
-								.join('\n\n')}
-					
-
- {/* Edit Pre-screen Questions Button */} - - - - - ); diff --git a/client/src/styles/SurveyDetailsCss.css b/client/src/styles/SurveyDetailsCss.css index ac090e3..aef2238 100644 --- a/client/src/styles/SurveyDetailsCss.css +++ b/client/src/styles/SurveyDetailsCss.css @@ -52,7 +52,6 @@ h3 { /* Edit Pre-Screen Responses Button */ .edit-button { - width: 100%; padding: 14px; background-color: #3e236e; color: white;