Skip to content

Commit

Permalink
Merge pull request #441 from sohosai/fix#439-2
Browse files Browse the repository at this point in the history
fix#439 SOS 管理人は申請の概要を変更できるようにする
  • Loading branch information
appare45 authored Aug 27, 2024
2 parents 1e5f232 + daadbd6 commit b84d81e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/app/committee/forms/[form_id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const EditFormPage: NextPage<{ params: { form_id: string } }> = ({ params }) =>
{!(!answerLoading && !answerError && asnwerData.length === 0) && (
<Link href={`/committee/forms/${params.form_id}`}>
<Button
visual="solid"
visual="outline"
color="purple"
className={css({
alignSelf: "center",
Expand Down
7 changes: 6 additions & 1 deletion src/app/committee/forms/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useRouter } from "next/navigation";
import toast from "react-hot-toast";
import { FormEditor, HandleFormEditorSubmit } from "@/common_components/form_editor/FormEditor";
import { deleteMultipleUploadedFiles } from "@/lib/postFile";
import Link from "next/link";

const CreateFormPage: NextPage = () => {
const router = useRouter();
Expand Down Expand Up @@ -43,14 +44,18 @@ const CreateFormPage: NextPage = () => {
padding: 5,
gap: 4,
})}>
{" "}
<Link href={`/committee/forms`} className={css({ color: "tsukuba.purple", display: "block" })}>
← 申請一覧に戻る
</Link>
<h1
className={css({
fontSize: "2xl",
fontWeight: "bold",
})}>
新規申請作成
</h1>
<FormEditor onSubmit={onSubmit} />
<FormEditor onSubmit={onSubmit} editable={true} />
</div>
);
};
Expand Down
69 changes: 53 additions & 16 deletions src/common_components/form_editor/FormEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { FilesField } from "./FilesEditor";
import { Button, buttonStyle } from "@/recipes/button";
import { FileView } from "@/common_components/FileView";

import useSWR from "swr";
import { assignType } from "@/lib/openapi";

export type FormField = {
name: string;
description?: string;
Expand Down Expand Up @@ -105,6 +108,22 @@ export const FormEditor: FC<{

const [fileErrors, setFileErrors] = useState<FileErrorsType>(new Map([["attachments", null]]));

const { data: data_user, isLoading: isLoading_user } = useSWR("/users/me");
const me = assignType("/users/me", data_user);
if (isLoading_user) {
return (
<div
className={css({
display: "flex",
justifyContent: "center",
alignItems: "center",
height: "85vh",
})}>
<p>読み込み中...</p>
</div>
);
}

return (
<>
<Divider />
Expand All @@ -116,7 +135,8 @@ export const FormEditor: FC<{
fontSize: "sm",
textAlign: "center",
})}>
すでに回答が存在するため、このフォームは編集できません。
すでに回答が存在するため、
{!isLoading_user && ["administrator"].includes(me.role) ? "設問部分" : "このフォーム"}は編集できません。
</p>
</>
)}
Expand Down Expand Up @@ -184,7 +204,11 @@ export const FormEditor: FC<{
checked={value.includes(category)}
ref={ref}
className={visuallyHidden()}
disabled={editable === false ? true : undefined}
disabled={
isLoading_user || (editable === false && ["administrator"].includes(me.role) === false)
? true
: undefined
}
/>
{getProjectCategoryText(category)}
</label>
Expand Down Expand Up @@ -216,7 +240,11 @@ export const FormEditor: FC<{
checked={value.includes(attribute)}
ref={ref}
className={visuallyHidden()}
disabled={editable === false ? true : undefined}
disabled={
isLoading_user || (editable === false && ["administrator"].includes(me.role) === false)
? true
: undefined
}
/>
{getProjectAttributeText(attribute)}
</label>
Expand All @@ -235,18 +263,26 @@ export const FormEditor: FC<{
<input
{...register("title", { required: true })}
className={textInputStyle}
disabled={editable === false ? true : undefined}
disabled={
isLoading_user || (editable === false && ["administrator"].includes(me.role) === false)
? true
: undefined
}
/>
</div>
<div>
<label htmlFor="description">説明</label>
<textarea
{...register("description", { required: true })}
className={textInputStyle}
disabled={editable === false ? true : undefined}
disabled={
isLoading_user || (editable === false && ["administrator"].includes(me.role) === false)
? true
: undefined
}
/>
</div>
{editable !== false ? (
{editable !== false || (!isLoading_user && ["administrator"].includes(me.role) === true) ? (
<div>
<label htmlFor="attachments">添付ファイル</label>
<FilesField
Expand Down Expand Up @@ -419,18 +455,19 @@ export const FormEditor: FC<{
</button>
</div>
</fieldset>

<Button
visual="solid"
color="purple"
className={css({
alignSelf: "center",
})}
disabled={isSubmitting || isSubmitSuccessful}>
送信
</Button>
</>
)}
{(editable !== false || (!isLoading_user && ["administrator"].includes(me.role) === true)) && (
<Button
visual="solid"
color="purple"
className={css({
alignSelf: "center",
})}
disabled={isSubmitting || isSubmitSuccessful}>
{defaultValues ? "更新" : "作成"}
</Button>
)}
</form>
</>
);
Expand Down

0 comments on commit b84d81e

Please sign in to comment.