diff --git a/user/src/components/Applications/Power/components/PowerFormView.tsx b/user/src/components/Applications/Power/components/PowerFormView.tsx index ee60f2098..644b6033d 100644 --- a/user/src/components/Applications/Power/components/PowerFormView.tsx +++ b/user/src/components/Applications/Power/components/PowerFormView.tsx @@ -31,7 +31,7 @@ export const PowerFormView: FC = ({ /> {/* 申請する場合のフォーム */} - {showForm && ( +
{fields.map((field, index) => ( @@ -74,7 +74,7 @@ export const PowerFormView: FC = ({
- )} + ); }; diff --git a/user/src/components/Applications/Power/hooks/usePowerApplication.ts b/user/src/components/Applications/Power/hooks/usePowerApplication.ts index c7ba8ac5e..0536f80b9 100644 --- a/user/src/components/Applications/Power/hooks/usePowerApplication.ts +++ b/user/src/components/Applications/Power/hooks/usePowerApplication.ts @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; import { useGetPowerOrders, useMutatePowerOrders } from '@/api/powerApi'; import { ORDER_TYPES, @@ -58,7 +58,14 @@ export const usePowerApplication = (groupId: number) => { const { submitPowerOrders, deletePowerOrder } = useMutatePowerOrders(); // フォーム管理 - const powerForm = usePowerForm(hasExisting ? { devices } : undefined); + const initialDefaultValues = useMemo(() => { + if (!hasExisting) return undefined; + + return { + devices: devices.map((d) => ({ ...d })), + }; + }, [hasExisting, devices]); + const powerForm = usePowerForm(initialDefaultValues); const { formMethods } = powerForm; // 状態更新のヘルパー関数