Skip to content

Commit

Permalink
fix: スキーマの更新によるビルドエラーを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
arata-nvm committed Apr 26, 2024
1 parent 401405d commit 3959cca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/common_components/formFields/_components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UseFormRegisterReturn } from "react-hook-form";
export type basicFieldProps = {
id: string;
label: string;
description?: string;
description?: string | null;
required?: boolean;
error?: string;
register: UseFormRegisterReturn;
Expand Down
44 changes: 19 additions & 25 deletions src/common_components/form_answer/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { client } from "@/lib/openapi";
import { deleteAllUploadedFiles, postFiles } from "@/lib/postFile";

import { components } from "@/schema";
import { FormItems, FileErrorsType, FormFieldsType, FilesFormType } from "./FormItems";
import { FileErrorsType, FilesFormType, FormFieldsType, FormItems } from "./FormItems";

import { buttonStyle } from "@/recipes/button";
import { sosFileType } from "@/lib/file";
Expand Down Expand Up @@ -39,30 +39,24 @@ export const Form = ({ form, answerId, answerItems, editable }: Props) => {

type formAnswerItems = components["schemas"]["CreateFormAnswer"]["items"];
const items: formAnswerItems = form.items.flatMap((item): formAnswerItems[number] | [] => {
const value = (() => {
switch (item.type) {
case "string":
return data[item.id] || null;
case "int":
const datum = data[item.id];
return datum ? parseInt(datum ?? "") : null;
case "file":
return fileIds[item.id] || null;
case "choose_many":
const options = JSON.parse(String(data[item.id] ?? "[]")) as string[];
return options.length ? options : null;
default:
return data[item.id] || null;
}
})();

return value
? {
item_id: item.id,
type: item.type,
value: value,
}
: [];
const datum = data[item.id];
switch (item.type) {
case "string":
if (!datum) return [];
return { item_id: item.id, type: item.type, value: datum };
case "int":
if (!datum) return [];
return { item_id: item.id, type: item.type, value: parseInt(datum) };
case "choose_one":
if (!datum) return [];
return { item_id: item.id, type: item.type, value: datum };
case "choose_many":
if (!datum) return [];
const options = JSON.parse(datum) as string[];
return options.length ? { item_id: item.id, type: item.type, value: options } : [];
case "file":
return { item_id: item.id, type: item.type, value: fileIds[item.id] };
}
});

if (answerItems) {
Expand Down
11 changes: 6 additions & 5 deletions src/common_components/form_editor/FormEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import { css } from "@styled-system/css";
import { FC, useState } from "react";
import { Controller, useFieldArray, useForm } from "react-hook-form";
import { ProjectAttribute, ProjectCategory, projectAttributes, projectCategories } from "@/lib/valibot";
import { getProjectCategoryText, getProjectAttributeText } from "@/lib/textUtils";
import { ProjectAttribute, projectAttributes, projectCategories, ProjectCategory } from "@/lib/valibot";
import { getProjectAttributeText, getProjectCategoryText } from "@/lib/textUtils";
import { stack, visuallyHidden } from "@styled-system/patterns";
import { FormFieldEditor } from "./FormFieldEditor";
import { sectionTitleStyle, descriptionStyle, checkboxGrpupStyle, checkboxStyle, textInputStyle } from "./styles";
import { checkboxGrpupStyle, checkboxStyle, descriptionStyle, sectionTitleStyle, textInputStyle } from "./styles";
import { components } from "@/schema";
import dayjs from "dayjs";
import { FileIds, postFiles } from "@/lib/postFile";
import toast from "react-hot-toast";
import { FilesFormType, FileErrorsType } from "@/common_components/form_answer/FormItems";
import { FileErrorsType, FilesFormType } from "@/common_components/form_answer/FormItems";
import { FilesField } from "@/common_components/formFields/Files";
import { Button, buttonStyle } from "@/recipes/button";

Expand All @@ -30,7 +30,7 @@ export type FormField = {
type: "string";
min_length?: number;
max_length?: number;
allow_newline?: boolean;
allow_newline: boolean;
}
| {
type: "choose_one";
Expand Down Expand Up @@ -272,6 +272,7 @@ export const FormEditor: FC<{
name: "",
required: false,
type: "string",
allow_newline: false,
});
}}>
テキスト項目
Expand Down

0 comments on commit 3959cca

Please sign in to comment.