Skip to content

Commit 55a76cb

Browse files
Merge pull request #1830 from hackforla/dev
Dev
2 parents 0ec084e + 7abbd33 commit 55a76cb

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

products/statement-generator/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ REACT_APP_SERVICE_DESCRIPTION=I check cakes for poison. It is a very serious job
1717
REACT_APP_COMPANY_NAME=Cool Company
1818
REACT_APP_JOB_TITLE=Big Boss
1919
REACT_APP_JOB_DESCRIPTION=I make the decisions on what the biggest cake should be.
20+
REACT_APP_IS_OTHER_JOB_CHECKED=True
21+
REACT_APP_OTHER_JOB_DESCRIPTION=I work at a volunteer tech non-profit.
2022

2123

2224
REACT_APP_NAME=Addicts Anonymous

products/statement-generator/public/locales/en/translation.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@
150150
"jobTitle_input_label": "What is your current job title?",
151151
"jobTitle_input_placeholder": "Job title",
152152
"jobDescription_input_label": "What do you do at this job? How has your role at work impacted your life for the better?\n(2-3 complete sentences)",
153-
"jobDescription_input_placeholder": ""
153+
"jobDescription_input_placeholder": "",
154+
"otherJob_label": "Do you have another job (or jobs) you would like to talk about?",
155+
"otherJobDescription_input_label": "Add information about your job (or jobs). Be sure to include the company's name and your job title. (3-5 complete sentences)",
156+
"otherJobDescription_input_placeholder": ""
154157
},
155158
"something_else_form": {
156159
"activityName_input_label": "What else have you been involved in?",

products/statement-generator/src/contexts/FormStateProps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export const defaultStepState = {
3737
companyName: '',
3838
jobTitle: '',
3939
jobDescription: '',
40+
isOtherJobChecked: '',
41+
otherJobDescription: '',
4042
},
4143
communityServiceState: {
4244
organizationName: '',
@@ -107,6 +109,8 @@ export interface IInvolvementJobState {
107109
companyName: string;
108110
jobTitle: string;
109111
jobDescription: string;
112+
isOtherJobChecked: string;
113+
otherJobDescription: string;
110114
}
111115
// step 2b
112116
export interface ICommunityServiceState {
@@ -182,6 +186,8 @@ export const sampleStepState = {
182186
companyName: process.env.REACT_APP_COMPANY_NAME,
183187
jobTitle: process.env.REACT_APP_JOB_TITLE,
184188
jobDescription: process.env.REACT_APP_JOB_DESCRIPTION,
189+
isOtherJobChecked: process.env.REACT_APP_IS_OTHER_JOB_CHECKED,
190+
otherJobDescription: process.env.REACT_APP_OTHER_JOB_DESCRIPTION,
185191
},
186192
communityServiceState: {
187193
organizationName: process.env.REACT_APP_ORGANIZATION_NAME,

products/statement-generator/src/helpers/statementGenerators.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ export function generateIntroduction(formState: IStepState): string {
2929
*/
3030
export function generateInvolvementJob(formState: IStepState): string {
3131
const {
32-
involvementJobState: { companyName, jobTitle, jobDescription },
32+
involvementJobState: {
33+
companyName,
34+
jobTitle,
35+
jobDescription,
36+
otherJobDescription,
37+
},
3338
} = formState;
3439

3540
if (!formState.involvement.isJobChecked) {
@@ -43,7 +48,13 @@ export function generateInvolvementJob(formState: IStepState): string {
4348
// Determine the correct article "a" or "an" based on the first letter of the jobTitle
4449
const article = generateArticle(jobTitle);
4550

46-
return `I have been working at ${companyName} as ${article} ${jobTitle}. At ${companyName}, ${jobDescription}`;
51+
let result = `I have been working at ${companyName} as ${article} ${jobTitle}. At ${companyName}, ${jobDescription}`;
52+
53+
if (otherJobDescription) {
54+
result += ` ${otherJobDescription}`;
55+
}
56+
57+
return result;
4758
}
4859

4960
/**

products/statement-generator/src/pages-form/InvolvementJobFlow.tsx

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import FormStateContext from 'contexts/FormStateContext';
55

66
import Input from 'components/Input';
77
import Textarea from 'components/Textarea';
8+
import RadioGroup from 'components/RadioGroup';
89
import FormFlowContainer from 'components-layout/FormFlowContainer';
910

1011
import {
@@ -20,21 +21,30 @@ function InvolvementJobFlow() {
2021
companyName,
2122
jobTitle,
2223
jobDescription,
24+
isOtherJobChecked,
25+
otherJobDescription,
2326
} = formState.involvementJobState;
2427

2528
const companyNameValid = companyName !== '';
2629
const jobTitleValid = jobTitle !== '';
27-
const jobDescriptionValid = jobDescription !== '';
30+
const jobDescriptionValid = /\w/.test(jobDescription || ''); // Check if contains any word character
31+
const otherJobDescriptionValid =
32+
isOtherJobChecked === t('button.no') ||
33+
(isOtherJobChecked === t('button.yes') &&
34+
/\w/.test(otherJobDescription || '')); // Check if contains any word character
2835
const isNextDisabled =
29-
!companyNameValid || !jobTitleValid || !jobDescriptionValid;
36+
!companyNameValid ||
37+
!jobTitleValid ||
38+
!jobDescriptionValid ||
39+
!otherJobDescriptionValid;
3040

3141
const onInputChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
3242
const { id, value } = evt.currentTarget;
3343
let formattedValue = value.trim();
3444

3545
if (id === 'companyName' || id === 'jobTitle') {
3646
formattedValue = capitalizeEachWord(value);
37-
} else if (id === 'jobDescription') {
47+
} else if (id === 'jobDescription' || id === 'otherJobDescription') {
3848
formattedValue = capitalizeSentences(value);
3949
}
4050

@@ -46,6 +56,17 @@ function InvolvementJobFlow() {
4656
});
4757
};
4858

59+
const onOtherJobChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
60+
const isChecked = evt.currentTarget.value === t('button.yes');
61+
updateStepToForm({
62+
involvementJobState: {
63+
...formState.involvementJobState,
64+
isOtherJobChecked: evt.currentTarget.value,
65+
...(isChecked ? {} : { otherJobDescription: '' }),
66+
},
67+
});
68+
};
69+
4970
const companyNameLabelRef = useRef<HTMLLabelElement>(null);
5071

5172
useEffect(() => {
@@ -84,6 +105,25 @@ function InvolvementJobFlow() {
84105
defaultValue={jobDescription}
85106
rows={3}
86107
/>
108+
109+
<RadioGroup
110+
id="otherJob"
111+
label={t('job_form.otherJob_label')}
112+
choices={[t('button.yes'), t('button.no')]}
113+
value={isOtherJobChecked}
114+
handleChange={onOtherJobChange}
115+
/>
116+
117+
{isOtherJobChecked === t('button.yes') && (
118+
<Textarea
119+
id="otherJobDescription"
120+
label={t('job_form.otherJobDescription_input_label')}
121+
placeholder={t('job_form.otherJobDescription_input_placeholder')}
122+
handleChange={onInputChange}
123+
defaultValue={otherJobDescription}
124+
rows={4}
125+
/>
126+
)}
87127
</FormFlowContainer>
88128
);
89129
}

0 commit comments

Comments
 (0)