ERP-node/frontend/lib/registry/components/mail-recipient-selector/MailRecipientSelectorConfig...

230 lines
8.0 KiB
TypeScript
Raw Normal View History

2025-12-09 13:29:20 +09:00
"use client";
/**
*
*
*/
import React, { useEffect, useState, useCallback } from "react";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import type { MailRecipientSelectorConfig } from "./types";
interface MailRecipientSelectorConfigPanelProps {
config: MailRecipientSelectorConfig;
onConfigChange: (config: MailRecipientSelectorConfig) => void;
}
export const MailRecipientSelectorConfigPanel: React.FC<MailRecipientSelectorConfigPanelProps> = ({
config,
onConfigChange,
}) => {
2025-12-09 13:29:20 +09:00
// 로컬 상태
const [localConfig, setLocalConfig] = useState<MailRecipientSelectorConfig>({
toFieldName: "mailTo",
ccFieldName: "mailCc",
showCc: true,
showInternalSelector: true,
showExternalInput: true,
toLabel: "수신자",
ccLabel: "참조(CC)",
required: true,
...config,
});
// config prop 변경 시 로컬 상태 동기화
useEffect(() => {
setLocalConfig({
toFieldName: "mailTo",
ccFieldName: "mailCc",
showCc: true,
showInternalSelector: true,
showExternalInput: true,
toLabel: "수신자",
ccLabel: "참조(CC)",
required: true,
...config,
});
}, [config]);
// 설정 업데이트 함수
const updateConfig = useCallback(
(key: keyof MailRecipientSelectorConfig, value: any) => {
const newConfig = { ...localConfig, [key]: value };
setLocalConfig(newConfig);
onConfigChange(newConfig);
},
[localConfig, onConfigChange],
2025-12-09 13:29:20 +09:00
);
return (
<div className="space-y-4">
{/* 필드명 설정 */}
<Card>
<CardHeader className="py-3">
<CardTitle className="text-sm"> </CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="space-y-1">
<Label className="text-xs"> </Label>
<Input
value={localConfig.toFieldName || "mailTo"}
onChange={(e) => updateConfig("toFieldName", e.target.value)}
placeholder="mailTo"
className="h-8 text-sm"
/>
<p className="text-[10px] text-gray-500">
formData에 ( {`{{mailTo}}`} )
</p>
</div>
<div className="space-y-1">
<Label className="text-xs"> </Label>
<Input
value={localConfig.ccFieldName || "mailCc"}
onChange={(e) => updateConfig("ccFieldName", e.target.value)}
placeholder="mailCc"
className="h-8 text-sm"
/>
<p className="text-[10px] text-gray-500">formData에 ( {`{{mailCc}}`} )</p>
2025-12-09 13:29:20 +09:00
</div>
</CardContent>
</Card>
{/* 표시 옵션 */}
<Card>
<CardHeader className="py-3">
<CardTitle className="text-sm"> </CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex items-center justify-between">
<div>
<Label className="text-xs">(CC) </Label>
<p className="text-[10px] text-gray-500"> </p>
</div>
<Switch
checked={localConfig.showCc !== false}
onCheckedChange={(checked) => updateConfig("showCc", checked)}
/>
</div>
<div className="flex items-center justify-between">
<div>
<Label className="text-xs"> </Label>
<p className="text-[10px] text-gray-500"> </p>
</div>
<Switch
checked={localConfig.showInternalSelector !== false}
onCheckedChange={(checked) => updateConfig("showInternalSelector", checked)}
2025-12-09 13:29:20 +09:00
/>
</div>
<div className="flex items-center justify-between">
<div>
<Label className="text-xs"> </Label>
<p className="text-[10px] text-gray-500"> </p>
</div>
<Switch
checked={localConfig.showExternalInput !== false}
onCheckedChange={(checked) => updateConfig("showExternalInput", checked)}
2025-12-09 13:29:20 +09:00
/>
</div>
<div className="flex items-center justify-between">
<div>
<Label className="text-xs"> </Label>
<p className="text-[10px] text-gray-500"> </p>
</div>
<Switch
checked={localConfig.required !== false}
onCheckedChange={(checked) => updateConfig("required", checked)}
/>
</div>
</CardContent>
</Card>
{/* 라벨 설정 */}
<Card>
<CardHeader className="py-3">
<CardTitle className="text-sm"> </CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="space-y-1">
<Label className="text-xs"> </Label>
<Input
value={localConfig.toLabel || "수신자"}
onChange={(e) => updateConfig("toLabel", e.target.value)}
placeholder="수신자"
className="h-8 text-sm"
/>
</div>
<div className="space-y-1">
<Label className="text-xs"> </Label>
<Input
value={localConfig.ccLabel || "참조(CC)"}
onChange={(e) => updateConfig("ccLabel", e.target.value)}
placeholder="참조(CC)"
className="h-8 text-sm"
/>
</div>
</CardContent>
</Card>
{/* 제한 설정 */}
<Card>
<CardHeader className="py-3">
<CardTitle className="text-sm"> </CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="space-y-1">
<Label className="text-xs"> </Label>
<Input
type="number"
value={localConfig.maxRecipients || ""}
onChange={(e) => updateConfig("maxRecipients", e.target.value ? parseInt(e.target.value) : undefined)}
2025-12-09 13:29:20 +09:00
placeholder="무제한"
className="h-8 text-sm"
/>
</div>
<div className="space-y-1">
<Label className="text-xs"> </Label>
<Input
type="number"
value={localConfig.maxCcRecipients || ""}
onChange={(e) => updateConfig("maxCcRecipients", e.target.value ? parseInt(e.target.value) : undefined)}
2025-12-09 13:29:20 +09:00
placeholder="무제한"
className="h-8 text-sm"
/>
</div>
</CardContent>
</Card>
{/* 사용 안내 */}
<Card className="bg-blue-50">
<CardContent className="p-3">
<div className="text-xs text-blue-700">
<p className="mb-1 font-medium"> </p>
<ol className="list-inside list-decimal space-y-1">
2025-12-09 13:29:20 +09:00
<li> .</li>
<li>
<code className="rounded bg-blue-100 px-1">{`{{mailTo}}`}</code>
.
2025-12-09 13:29:20 +09:00
</li>
<li>
<code className="rounded bg-blue-100 px-1">{`{{mailCc}}`}</code> .
2025-12-09 13:29:20 +09:00
</li>
<li> .</li>
</ol>
</div>
</CardContent>
</Card>
</div>
);
};
export default MailRecipientSelectorConfigPanel;