Skip to content

Commit

Permalink
fix: crash when only one available storage class
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 committed Nov 21, 2024
1 parent 172976c commit 6df9649
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
61 changes: 32 additions & 29 deletions src/renderer/components/forms/change-storage-class-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import StorageClass from "@common/models/storage-class";

export interface ChangeStorageClassFormData {
storageClassKodoName: string,
someInput: string,
}

interface ChangeStorageClassFormProps {
Expand Down Expand Up @@ -52,7 +51,7 @@ const ChangeStorageClassForm: React.FC<ChangeStorageClassFormProps> = ({

useEffect(() => {
reset({
storageClassKodoName: availableStorageClasses[0].kodoName ?? "Standard",
storageClassKodoName: availableStorageClasses[0]?.kodoName ?? "",
});
}, []);

Expand Down Expand Up @@ -97,33 +96,37 @@ const ChangeStorageClassForm: React.FC<ChangeStorageClassFormProps> = ({
</div>
</Form.Group>
}
<Form.Group as={Fragment} controlId="storageClassKodoName">
<Form.Label className="text-end">
{translate("forms.changeStorageClass.storageClassKodoName.label")}
</Form.Label>
<div>
{
availableStorageClasses.map(storageClass => (
<Form.Check
{...register("storageClassKodoName")}
id={`storageClassKodoName-${storageClass.kodoName}`}
key={storageClass.kodoName}
type="radio"
label={storageClass.nameI18n[currentLanguage]}
value={storageClass.kodoName}
/>
))
}
<Form.Text>
{
availableStorageClasses
.find(storageClasses =>
storageClasses.kodoName === watch("storageClassKodoName"))
?.billingI18n[currentLanguage]
}
</Form.Text>
</div>
</Form.Group>
{
!availableStorageClasses.length
? null
: <Form.Group as={Fragment} controlId="storageClassKodoName">
<Form.Label className="text-end">
{translate("forms.changeStorageClass.storageClassKodoName.label")}
</Form.Label>
<div>
{
availableStorageClasses.map(storageClass => (
<Form.Check
{...register("storageClassKodoName")}
id={`storageClassKodoName-${storageClass.kodoName}`}
key={storageClass.kodoName}
type="radio"
label={storageClass.nameI18n[currentLanguage]}
value={storageClass.kodoName}
/>
))
}
<Form.Text>
{
availableStorageClasses
.find(storageClasses =>
storageClasses.kodoName === watch("storageClassKodoName"))
?.billingI18n[currentLanguage]
}
</Form.Text>
</div>
</Form.Group>
}
</fieldset>
</Form>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ const ChangeFileStorageClass: React.FC<ModalProps & ChangeFileStorageClassProps>
const changeStorageClassFormController = useForm<ChangeStorageClassFormData>({
mode: "onChange",
defaultValues: {
storageClassKodoName: storageClasses[0]?.kodoName ?? "Standard",
storageClassKodoName: storageClasses[0]?.kodoName ?? "",
},
});

const {
watch,
handleSubmit,
formState: {
isSubmitting,
Expand Down Expand Up @@ -135,7 +136,7 @@ const ChangeFileStorageClass: React.FC<ModalProps & ChangeFileStorageClassProps>
</Modal.Body>
<Modal.Footer>
{
!memoFileItem || isSubmitSuccessful
!memoFileItem || !watch("storageClassKodoName") || isSubmitSuccessful
? null
: <Button
variant="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const ChangeFilesStorageClass: React.FC<ModalProps & ChangeFilesStorageClassProp
const changeStorageClassFormController = useForm<ChangeStorageClassFormData>({
mode: "onChange",
defaultValues: {
storageClassKodoName: storageClasses[0]?.kodoName ?? "Standard",
storageClassKodoName: storageClasses[0]?.kodoName ?? "",
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ const ChangeStorageClass: React.FC<ChangeStorageClassProps> = ({
const changeStorageClassFormController = useForm<ChangeStorageClassFormData>({
mode: "onChange",
defaultValues: {
storageClassKodoName: storageClasses[0]?.kodoName ?? "Standard",
storageClassKodoName: storageClasses[0]?.kodoName ?? "",
},
});

const {
watch,
handleSubmit,
formState: {
isSubmitting,
Expand Down Expand Up @@ -123,7 +124,7 @@ const ChangeStorageClass: React.FC<ChangeStorageClassProps> = ({
onSubmit={handleSubmitChangeStorageClass}
/>
{
!SubmitButtonPortal || isSubmitSuccessful
!SubmitButtonPortal || !watch("storageClassKodoName") || isSubmitSuccessful
? null
: <SubmitButtonPortal>
<Button
Expand Down

0 comments on commit 6df9649

Please sign in to comment.