79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
import { Label } from "@/components/ui/label";
|
|
import type { listHeader } from "@/types/list";
|
|
import type { ProjectSurvey } from "@/types/project";
|
|
|
|
type MessageVariableListProps = {
|
|
listHeaders: listHeader[];
|
|
surveys: ProjectSurvey[];
|
|
onInsert: (value: string) => void;
|
|
};
|
|
|
|
type VariableRowProps = {
|
|
id: string;
|
|
name: string;
|
|
value: string;
|
|
onInsert: (value: string) => void;
|
|
};
|
|
|
|
const VariableRow = ({ id, name, value, onInsert }: VariableRowProps) => (
|
|
<div
|
|
key={id}
|
|
className="grid cursor-pointer grid-cols-2 border-b transition-colors last:border-b-0 hover:bg-blue-50"
|
|
onPointerDown={(event) => {
|
|
event.preventDefault();
|
|
onInsert(value);
|
|
}}
|
|
>
|
|
<div className="px-3 py-2 text-center text-sm border-r">{name}</div>
|
|
<div className="min-w-0 break-all px-3 py-2 text-center text-sm" title={value}>
|
|
{value}
|
|
</div>
|
|
</div>
|
|
);
|
|
|
|
export const MessageVariableList = ({ listHeaders, surveys, onInsert }: MessageVariableListProps) => {
|
|
const availableSurveys = surveys.filter((survey) => survey.surveyUrl?.trim());
|
|
|
|
return (
|
|
<div className="space-y-3">
|
|
<div className="flex items-center">
|
|
<Label className="text-base">변수 리스트</Label>
|
|
</div>
|
|
|
|
<div className="overflow-hidden rounded-md border">
|
|
<div className="grid grid-cols-2 border-b bg-blue-100">
|
|
<div className="border-r px-3 py-2 text-center text-base font-medium">리스트 헤더명</div>
|
|
<div className="px-3 py-2 text-center text-base font-medium">치환 문자</div>
|
|
</div>
|
|
|
|
<div className="max-h-50 overflow-y-auto">
|
|
{listHeaders.map((header) => {
|
|
const placeholder = `[$${header.listHderNm}]`;
|
|
return (
|
|
<VariableRow
|
|
key={`header-${header.listHderId}`}
|
|
id={`header-${header.listHderId}`}
|
|
name={header.listHderNm}
|
|
value={placeholder}
|
|
onInsert={onInsert}
|
|
/>
|
|
);
|
|
})}
|
|
{availableSurveys.map((survey) => {
|
|
const surveyUrl = survey.surveyUrl?.trim() ?? "";
|
|
return (
|
|
<VariableRow
|
|
key={`survey-${survey.prjctSurveyIdx ?? survey.surveyOrder}`}
|
|
id={`survey-${survey.prjctSurveyIdx ?? survey.surveyOrder}`}
|
|
name={survey.surveyName}
|
|
value={surveyUrl}
|
|
onInsert={onInsert}
|
|
/>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|