Skip to content

Commit 3323f7d

Browse files
committed
fix: crash when only one available storage class
1 parent 659e720 commit 3323f7d

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

src/renderer/components/forms/change-storage-class-form.tsx

+32-29
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import StorageClass from "@common/models/storage-class";
77

88
export interface ChangeStorageClassFormData {
99
storageClassKodoName: string,
10-
someInput: string,
1110
}
1211

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

5352
useEffect(() => {
5453
reset({
55-
storageClassKodoName: availableStorageClasses[0].kodoName ?? "Standard",
54+
storageClassKodoName: availableStorageClasses[0]?.kodoName ?? "",
5655
});
5756
}, []);
5857

@@ -97,33 +96,37 @@ const ChangeStorageClassForm: React.FC<ChangeStorageClassFormProps> = ({
9796
</div>
9897
</Form.Group>
9998
}
100-
<Form.Group as={Fragment} controlId="storageClassKodoName">
101-
<Form.Label className="text-end">
102-
{translate("forms.changeStorageClass.storageClassKodoName.label")}
103-
</Form.Label>
104-
<div>
105-
{
106-
availableStorageClasses.map(storageClass => (
107-
<Form.Check
108-
{...register("storageClassKodoName")}
109-
id={`storageClassKodoName-${storageClass.kodoName}`}
110-
key={storageClass.kodoName}
111-
type="radio"
112-
label={storageClass.nameI18n[currentLanguage]}
113-
value={storageClass.kodoName}
114-
/>
115-
))
116-
}
117-
<Form.Text>
118-
{
119-
availableStorageClasses
120-
.find(storageClasses =>
121-
storageClasses.kodoName === watch("storageClassKodoName"))
122-
?.billingI18n[currentLanguage]
123-
}
124-
</Form.Text>
125-
</div>
126-
</Form.Group>
99+
{
100+
!availableStorageClasses.length
101+
? null
102+
: <Form.Group as={Fragment} controlId="storageClassKodoName">
103+
<Form.Label className="text-end">
104+
{translate("forms.changeStorageClass.storageClassKodoName.label")}
105+
</Form.Label>
106+
<div>
107+
{
108+
availableStorageClasses.map(storageClass => (
109+
<Form.Check
110+
{...register("storageClassKodoName")}
111+
id={`storageClassKodoName-${storageClass.kodoName}`}
112+
key={storageClass.kodoName}
113+
type="radio"
114+
label={storageClass.nameI18n[currentLanguage]}
115+
value={storageClass.kodoName}
116+
/>
117+
))
118+
}
119+
<Form.Text>
120+
{
121+
availableStorageClasses
122+
.find(storageClasses =>
123+
storageClasses.kodoName === watch("storageClassKodoName"))
124+
?.billingI18n[currentLanguage]
125+
}
126+
</Form.Text>
127+
</div>
128+
</Form.Group>
129+
}
127130
</fieldset>
128131
</Form>
129132
);

src/renderer/components/modals/file/change-file-storage-class/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ const ChangeFileStorageClass: React.FC<ModalProps & ChangeFileStorageClassProps>
5858
const changeStorageClassFormController = useForm<ChangeStorageClassFormData>({
5959
mode: "onChange",
6060
defaultValues: {
61-
storageClassKodoName: storageClasses[0]?.kodoName ?? "Standard",
61+
storageClassKodoName: storageClasses[0]?.kodoName ?? "",
6262
},
6363
});
6464

6565
const {
66+
watch,
6667
handleSubmit,
6768
formState: {
6869
isSubmitting,
@@ -135,7 +136,7 @@ const ChangeFileStorageClass: React.FC<ModalProps & ChangeFileStorageClassProps>
135136
</Modal.Body>
136137
<Modal.Footer>
137138
{
138-
!memoFileItem || isSubmitSuccessful
139+
!memoFileItem || !watch("storageClassKodoName") || isSubmitSuccessful
139140
? null
140141
: <Button
141142
variant="primary"

src/renderer/components/modals/file/change-files-storage-class/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const ChangeFilesStorageClass: React.FC<ModalProps & ChangeFilesStorageClassProp
8787
const changeStorageClassFormController = useForm<ChangeStorageClassFormData>({
8888
mode: "onChange",
8989
defaultValues: {
90-
storageClassKodoName: storageClasses[0]?.kodoName ?? "Standard",
90+
storageClassKodoName: storageClasses[0]?.kodoName ?? "",
9191
},
9292
});
9393

src/renderer/components/modals/preview-file/file-operation/change-storage-class.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ const ChangeStorageClass: React.FC<ChangeStorageClassProps> = ({
6262
const changeStorageClassFormController = useForm<ChangeStorageClassFormData>({
6363
mode: "onChange",
6464
defaultValues: {
65-
storageClassKodoName: storageClasses[0]?.kodoName ?? "Standard",
65+
storageClassKodoName: storageClasses[0]?.kodoName ?? "",
6666
},
6767
});
6868

6969
const {
70+
watch,
7071
handleSubmit,
7172
formState: {
7273
isSubmitting,
@@ -123,7 +124,7 @@ const ChangeStorageClass: React.FC<ChangeStorageClassProps> = ({
123124
onSubmit={handleSubmitChangeStorageClass}
124125
/>
125126
{
126-
!SubmitButtonPortal || isSubmitSuccessful
127+
!SubmitButtonPortal || !watch("storageClassKodoName") || isSubmitSuccessful
127128
? null
128129
: <SubmitButtonPortal>
129130
<Button

0 commit comments

Comments
 (0)