Skip to content

Commit 02f42af

Browse files
authored
feat(AccessCode): hide code inputs for offline codes (#606)
1 parent 7032b69 commit 02f42af

File tree

1 file changed

+74
-67
lines changed

1 file changed

+74
-67
lines changed

src/lib/ui/AccessCodeForm/AccessCodeForm.tsx

Lines changed: 74 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ function Content({
176176
? t.codeLengthRequirement(codeLengthRequirement)
177177
: null
178178

179+
const hasCodeInputs =
180+
accessCode?.type !== 'time_bound' || accessCode.is_offline_access_code
181+
179182
return (
180183
<>
181184
<ContentHeader
@@ -207,77 +210,81 @@ function Content({
207210
}}
208211
/>
209212
</FormField>
210-
<FormField className='seam-code-field'>
211-
<InputLabel>{t.codeInputLabel}</InputLabel>
212-
<TextField
213-
size='large'
214-
clearable
215-
hasError={hasCodeError}
216-
helperText={responseErrors?.code ?? errors.code?.message}
217-
inputProps={{
218-
...register('code', {
219-
required: t.codeRequiredError,
220-
validate: (value: string) =>
221-
validateCodeLength(device, value),
222-
}),
223-
}}
224-
/>
225-
<div
226-
className={classNames('seam-bottom', {
227-
'has-hints': codeLengthRequirementMessage != null,
228-
})}
229-
>
230-
{codeLengthRequirementMessage != null && (
231-
<ul
232-
className={classNames('seam-requirements', {
233-
'seam-error': hasCodeError,
234-
})}
235-
>
236-
<li>{codeLengthRequirementMessage}</li>
237-
<li>{t.codeNumbersOnlyRequirement}</li>
238-
</ul>
239-
)}
240-
<Button
241-
size='small'
242-
onMouseDown={(e) => {
243-
e.preventDefault() // Disable stealing input focus
244-
handleGenerateCode()
245-
}}
246-
disabled={isGeneratingCode}
247-
>
248-
{t.codeGenerateButton}
249-
</Button>
250-
</div>
251-
</FormField>
252-
<FormField>
253-
<InputLabel>{t.timingInputLabel}</InputLabel>
254-
<RadioField
255-
value={type}
256-
onChange={setType}
257-
name='type'
258-
options={[
259-
{
260-
label: t.typeOngoingLabel,
261-
value: 'ongoing',
262-
},
263-
{
264-
label: t.typeTimeBoundLabel,
265-
value: 'time_bound',
266-
},
267-
]}
268-
/>
213+
{hasCodeInputs && (
269214
<>
270-
{type === 'time_bound' && (
271-
<AccessCodeFormTimes
272-
startDate={startDate}
273-
endDate={endDate}
274-
onEdit={() => {
275-
setDatePickerVisible(true)
215+
<FormField className='seam-code-field'>
216+
<InputLabel>{t.codeInputLabel}</InputLabel>
217+
<TextField
218+
size='large'
219+
clearable
220+
hasError={hasCodeError}
221+
helperText={responseErrors?.code ?? errors.code?.message}
222+
inputProps={{
223+
...register('code', {
224+
required: t.codeRequiredError,
225+
validate: (value: string) =>
226+
validateCodeLength(device, value),
227+
}),
276228
}}
277229
/>
278-
)}
230+
<div
231+
className={classNames('seam-bottom', {
232+
'has-hints': codeLengthRequirementMessage != null,
233+
})}
234+
>
235+
{codeLengthRequirementMessage != null && (
236+
<ul
237+
className={classNames('seam-requirements', {
238+
'seam-error': hasCodeError,
239+
})}
240+
>
241+
<li>{codeLengthRequirementMessage}</li>
242+
<li>{t.codeNumbersOnlyRequirement}</li>
243+
</ul>
244+
)}
245+
<Button
246+
size='small'
247+
onMouseDown={(e) => {
248+
e.preventDefault() // Disable stealing input focus
249+
handleGenerateCode()
250+
}}
251+
disabled={isGeneratingCode}
252+
>
253+
{t.codeGenerateButton}
254+
</Button>
255+
</div>
256+
</FormField>
257+
<FormField>
258+
<InputLabel>{t.timingInputLabel}</InputLabel>
259+
<RadioField
260+
value={type}
261+
onChange={setType}
262+
name='type'
263+
options={[
264+
{
265+
label: t.typeOngoingLabel,
266+
value: 'ongoing',
267+
},
268+
{
269+
label: t.typeTimeBoundLabel,
270+
value: 'time_bound',
271+
},
272+
]}
273+
/>
274+
<>
275+
{type === 'time_bound' && (
276+
<AccessCodeFormTimes
277+
startDate={startDate}
278+
endDate={endDate}
279+
onEdit={() => {
280+
setDatePickerVisible(true)
281+
}}
282+
/>
283+
)}
284+
</>
285+
</FormField>
279286
</>
280-
</FormField>
287+
)}
281288
{responseErrors?.unknown != null && (
282289
<div className='seam-unknown-error'>{responseErrors?.unknown}</div>
283290
)}

0 commit comments

Comments
 (0)