Skip to content
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

fix: Unable to edit time_bound access codes #656

Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 77 additions & 76 deletions src/lib/ui/AccessCodeForm/AccessCodeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ function Content({
}

const start = startDate.toISO()
if (start == null) {
if (start === null || start === undefined) {
throw new Error(`Invalid start date: ${startDate.invalidReason}`)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (start === null || start === undefined) {
throw new Error(`Invalid start date: ${startDate.invalidReason}`)
}
if (start === null) {
throw new Error(`Invalid start date: ${startDate.invalidReason}`)
}


const end = endDate.toISO()
if (end == null) {
if (end === null || end === undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (end === null || end === undefined) {
if (end === null) {

throw new Error(`Invalid end date: ${endDate.invalidReason}`)
}

Expand Down Expand Up @@ -172,8 +172,7 @@ function Content({
? t.codeLengthRequirement(codeLengthRequirement)
: null

const hasCodeInputs =
accessCode?.type !== 'time_bound' || accessCode.is_offline_access_code
const hasCodeInputs = accessCode?.type !== 'time_bound'

return (
<>
Expand Down Expand Up @@ -206,81 +205,83 @@ function Content({
}}
/>
</FormField>
{hasCodeInputs && (
<>
<FormField className='seam-code-field'>
<InputLabel>{t.codeInputLabel}</InputLabel>
<TextField
size='large'
clearable
hasError={hasCodeError}
helperText={responseErrors?.code ?? errors.code?.message}
inputProps={{
...register('code', {
required: t.codeRequiredError,
validate: (value: string) =>
validateCodeLength(device, value),
}),
}}
/>
<div
className={classNames('seam-bottom', {
'has-hints': codeLengthRequirementMessage != null,
})}
>
{codeLengthRequirementMessage != null && (
<ul
className={classNames('seam-requirements', {
'seam-error': hasCodeError,
})}
>
<li>{codeLengthRequirementMessage}</li>
<li>{t.codeNumbersOnlyRequirement}</li>
</ul>
)}
<Button
size='small'
onMouseDown={(e) => {
e.preventDefault() // Disable stealing input focus
handleGenerateCode()
{hasCodeInputs !== null &&
hasCodeInputs !== undefined &&
hasCodeInputs && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{hasCodeInputs !== null &&
hasCodeInputs !== undefined &&
hasCodeInputs && (
{hasCodeInputs && (

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's redundant, I have removed it now

<>
<FormField className='seam-code-field'>
<InputLabel>{t.codeInputLabel}</InputLabel>
<TextField
size='large'
clearable
hasError={hasCodeError}
helperText={responseErrors?.code ?? errors.code?.message}
inputProps={{
...register('code', {
required: t.codeRequiredError,
validate: (value: string) =>
validateCodeLength(device, value),
}),
}}
disabled={isGeneratingCode}
/>
<div
className={classNames('seam-bottom', {
'has-hints': codeLengthRequirementMessage != null,
})}
>
{t.codeGenerateButton}
</Button>
</div>
</FormField>
<FormField>
<InputLabel>{t.timingInputLabel}</InputLabel>
<RadioField
value={type}
onChange={setType}
name='type'
options={[
{
label: t.typeOngoingLabel,
value: 'ongoing',
},
{
label: t.typeTimeBoundLabel,
value: 'time_bound',
},
]}
/>
<>
{type === 'time_bound' && (
<AccessCodeFormTimes
startDate={startDate}
endDate={endDate}
onEdit={() => {
setDatePickerVisible(true)
{codeLengthRequirementMessage != null && (
<ul
className={classNames('seam-requirements', {
'seam-error': hasCodeError,
})}
>
<li>{codeLengthRequirementMessage}</li>
<li>{t.codeNumbersOnlyRequirement}</li>
</ul>
)}
<Button
size='small'
onMouseDown={(e) => {
e.preventDefault() // Disable stealing input focus
handleGenerateCode()
}}
/>
)}
</>
</FormField>
</>
)}
disabled={isGeneratingCode}
>
{t.codeGenerateButton}
</Button>
</div>
</FormField>
<FormField>
<InputLabel>{t.timingInputLabel}</InputLabel>
<RadioField
value={type}
onChange={setType}
name='type'
options={[
{
label: t.typeOngoingLabel,
value: 'ongoing',
},
{
label: t.typeTimeBoundLabel,
value: 'time_bound',
},
]}
/>
<>
{type === 'time_bound' && (
<AccessCodeFormTimes
startDate={startDate}
endDate={endDate}
onEdit={() => {
setDatePickerVisible(true)
}}
/>
)}
</>
</FormField>
</>
)}
{responseErrors?.unknown != null && (
<div className='seam-unknown-error'>{responseErrors?.unknown}</div>
)}
Expand Down
Loading