Skip to content

Commit 3aee4c5

Browse files
authored
Merge pull request #1216 from userlocalhost/feature/ui/more_reusability
Fixed some common components to be more reusability
2 parents 8273f56 + 4f42355 commit 3aee4c5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

frontend/src/components/common/SubmitButton.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface Props {
1616
disabled: boolean;
1717
isSubmitting: boolean;
1818
handleSubmit: React.MouseEventHandler<HTMLButtonElement>;
19-
handleCancel: React.MouseEventHandler<HTMLButtonElement>;
19+
handleCancel?: React.MouseEventHandler<HTMLButtonElement>;
2020
}
2121

2222
export const SubmitButton: FC<Props> = ({
@@ -37,9 +37,11 @@ export const SubmitButton: FC<Props> = ({
3737
{name}
3838
{isSubmitting && <CircularProgress size="20px" />}
3939
</StyledButton>
40-
<StyledButton variant="contained" color="info" onClick={handleCancel}>
41-
キャンセル
42-
</StyledButton>
40+
{handleCancel && (
41+
<StyledButton variant="contained" color="info" onClick={handleCancel}>
42+
キャンセル
43+
</StyledButton>
44+
)}
4345
</StyledBox>
4446
);
4547
};

frontend/src/services/AironeAPIErrorUtil.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,15 @@ export const extractAPIException = async <T>(
118118
const details = (typed as Record<string, Array<ErrorDetail>>)[fieldName];
119119
const message = details.map((e) => extractErrorDetail(e)).join(", ");
120120

121-
fieldReporter(fieldName as keyof T, message);
121+
// This convert snake_case to camelCase (e.g. "nw_addr" -> "nwAddr")
122+
const snakeToCamel = (x: string) =>
123+
x
124+
.toLowerCase()
125+
.replace(/(_\w)/g, (m: string) => m.toUpperCase().substr(1));
126+
127+
// It's necessary to convert fieldName from snake case to cammel case because
128+
// server-side response its name as snake case but zod expect it as camel case.
129+
fieldReporter(snakeToCamel(fieldName) as keyof T, message);
122130
});
123131
};
124132

0 commit comments

Comments
 (0)