-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add gas utility selector #197
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,11 +38,15 @@ const HOUSEHOLD_SIZE_OPTIONS: ( | |
value: count, | ||
})); | ||
|
||
const NO_GAS_UTILITY_ID = 'no-gas'; | ||
const DELIVERED_FUEL_UTILITY_ID = 'delivered'; | ||
const OTHER_UTILITY_ID = 'other'; | ||
|
||
const renderUtilityField = ( | ||
const renderUtilityFields = ( | ||
utility: string, | ||
setUtility: (newValue: string) => void, | ||
gasUtility: string, | ||
setGasUtility: (newValue: string) => void, | ||
utilitiesFetch: FetchState<APIUtilitiesResponse>, | ||
msg: MsgFn, | ||
) => { | ||
|
@@ -67,7 +71,7 @@ const renderUtilityField = ( | |
: msg('We don’t have utility data for your area yet.') | ||
: utilitiesFetch.message; | ||
|
||
return ( | ||
const electricSelector = ( | ||
<Select | ||
id="utility" | ||
labelText={msg('Electric Utility', { desc: 'as in utility company' })} | ||
|
@@ -81,6 +85,53 @@ const renderUtilityField = ( | |
loading={utilitiesFetch.state === 'loading'} | ||
/> | ||
); | ||
|
||
let gasSelector = null; | ||
const gasUtilities = | ||
utilitiesFetch.state === 'complete' | ||
? utilitiesFetch.response.gas_utilities | ||
: utilitiesFetch.state === 'loading' | ||
? utilitiesFetch.previousResponse?.gas_utilities | ||
: null; | ||
|
||
// If the response does not contain the gas utilities key, that means the | ||
// user's gas utility is irrelevant, so we don't show the selector. If the key | ||
// is present, we need to show the selector even if the gas utilities map is | ||
// empty, because it matters whether the user actually has no gas service, or | ||
// has gas service that's not listed here (indicated by the Other item). | ||
if (gasUtilities) { | ||
const gasOptions = Object.entries(gasUtilities) | ||
.map(([id, info]) => ({ value: id, label: info.name })) | ||
.concat([ | ||
{ | ||
value: DELIVERED_FUEL_UTILITY_ID, | ||
label: msg('Delivered propane or fuel oil'), | ||
}, | ||
{ value: NO_GAS_UTILITY_ID, label: msg('No gas service') }, | ||
{ value: OTHER_UTILITY_ID, label: msg('Other') }, | ||
]); | ||
gasSelector = ( | ||
<Select | ||
id="gas_utility" | ||
labelText={msg('Gas Utility', { desc: 'as in utility company' })} | ||
tooltipText={msg('Choose the company you pay your gas bill to.')} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (no change required) "to which you pay your gas bill" if probably more grammatically correct but also overly formal, hmmm... |
||
placeholder={msg('Select utility')} | ||
disabled={ | ||
gasOptions.length === 0 || utilitiesFetch.state !== 'complete' | ||
} | ||
options={gasOptions} | ||
currentValue={gasUtility} | ||
onChange={setGasUtility} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
{electricSelector} | ||
{gasSelector} | ||
</> | ||
); | ||
}; | ||
|
||
const renderEmailField = ( | ||
|
@@ -144,6 +195,7 @@ export type FormValues = { | |
householdSize: string; | ||
taxFiling: FilingStatus; | ||
utility?: string; | ||
gasUtility?: string; | ||
email?: string; | ||
}; | ||
|
||
|
@@ -174,6 +226,7 @@ export const CalculatorForm: FC<{ | |
); | ||
const [taxFiling, setTaxFiling] = useState(initialValues.taxFiling); | ||
const [utility, setUtility] = useState(initialValues.utility ?? ''); | ||
const [gasUtility, setGasUtility] = useState(initialValues.gasUtility ?? ''); | ||
const [email, setEmail] = useState(initialValues.email ?? ''); | ||
|
||
const [utilitiesFetchState, setUtilitiesFetchState] = useState< | ||
|
@@ -187,13 +240,17 @@ export const CalculatorForm: FC<{ | |
return; | ||
} | ||
|
||
setUtilitiesFetchState({ state: 'loading' }); | ||
setUtilitiesFetchState(prev => ({ | ||
state: 'loading', | ||
previousResponse: prev.state === 'complete' ? prev.response : undefined, | ||
})); | ||
utilityFetcher(zip) | ||
.then(response => { | ||
// If our "state" attribute is set, enforce that the entered location is | ||
// in that state. | ||
if (stateId && stateId !== response.location.state) { | ||
setUtility(''); | ||
setGasUtility(''); | ||
|
||
// Throw to put the task into the ERROR state for rendering. | ||
const stateCodeOrName = STATES[stateId]?.name(msg) ?? stateId; | ||
|
@@ -214,6 +271,16 @@ export const CalculatorForm: FC<{ | |
} else { | ||
setUtility(OTHER_UTILITY_ID); | ||
} | ||
|
||
const gasKeys = Object.keys(response.gas_utilities || {}); | ||
if (gasKeys.length > 0) { | ||
if (!gasKeys.includes(gasUtility)) { | ||
setGasUtility(gasKeys[0]); | ||
} | ||
} else { | ||
// If there are no gas utilities, choose the "no gas service" option. | ||
setGasUtility(NO_GAS_UTILITY_ID); | ||
} | ||
}) | ||
.catch(exc => | ||
setUtilitiesFetchState({ state: 'error', message: exc.message }), | ||
|
@@ -231,6 +298,13 @@ export const CalculatorForm: FC<{ | |
householdSize, | ||
taxFiling, | ||
utility: utility !== OTHER_UTILITY_ID ? utility : '', | ||
gasUtility: | ||
gasUtility === OTHER_UTILITY_ID | ||
? '' | ||
: gasUtility === DELIVERED_FUEL_UTILITY_ID || | ||
gasUtility === NO_GAS_UTILITY_ID | ||
? 'none' | ||
: '', | ||
email, | ||
}); | ||
}} | ||
|
@@ -273,7 +347,14 @@ export const CalculatorForm: FC<{ | |
onChange={event => setZip(event.currentTarget.value)} | ||
/> | ||
</div> | ||
{renderUtilityField(utility, setUtility, utilitiesFetchState, msg)} | ||
{renderUtilityFields( | ||
utility, | ||
setUtility, | ||
gasUtility, | ||
setGasUtility, | ||
utilitiesFetchState, | ||
msg, | ||
)} | ||
<div> | ||
<FormLabel | ||
tooltipText={msg( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -786,6 +786,21 @@ | |
<source>privacy policy</source> | ||
<target>política de privacidad</target> | ||
</trans-unit> | ||
<trans-unit id="sb2d056e8d2ea5bc5"> | ||
<source>Delivered propane or fuel oil</source> | ||
</trans-unit> | ||
<trans-unit id="s52d768131ca697d4"> | ||
<source>No gas service</source> | ||
</trans-unit> | ||
Comment on lines
+789
to
+794
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you waiting on translations for this? |
||
<trans-unit id="sc967ff75e8a58273"> | ||
<source>Choose the company you pay your gas bill to.</source> | ||
<target>Selecciona la empresa a la que paga su factura de gas.</target> | ||
</trans-unit> | ||
<trans-unit id="sab68e846cf3e7e02"> | ||
<source>Gas Utility</source> | ||
<target>Empresa de gas</target> | ||
<note from="lit-localize">as in utility company</note> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this supposed to be en español?