- create: 템플릿 선택 시 PDF required 제거, 안내 메시지 표시
- fields: PDF 없는 계약 시 업로드 UI 표시
- API: uploadPdf 엔드포인트 추가 (POST /{id}/upload-pdf)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
266 lines
16 KiB
PHP
266 lines
16 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('title', 'SAM E-Sign - 새 계약 생성')
|
|
|
|
@section('content')
|
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
<div id="esign-create-root"></div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
@include('partials.react-cdn')
|
|
<script>
|
|
window.__esignCreate = {
|
|
isAdmin: @json(auth()->user()?->is_super_admin || auth()->user()?->hasRole(['admin', 'super-admin'])),
|
|
};
|
|
</script>
|
|
@verbatim
|
|
<script type="text/babel">
|
|
const { useState, useEffect, useRef } = React;
|
|
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.content || '';
|
|
const IS_ADMIN = window.__esignCreate?.isAdmin || false;
|
|
|
|
const Input = ({ label, name, value, error, onChange, type = 'text', required = false, placeholder = '', style }) => (
|
|
<div style={style}>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">{label} {required && <span className="text-red-500">*</span>}</label>
|
|
<input type={type} value={value} onChange={e => onChange(name, e.target.value)}
|
|
placeholder={placeholder} required={required}
|
|
className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none transition-colors" />
|
|
{error && <p className="text-red-500 text-xs mt-1">{error}</p>}
|
|
</div>
|
|
);
|
|
|
|
const SignerRow = ({ prefix, title, subtitle, color, form, errors, onChange }) => (
|
|
<div>
|
|
<div className="flex items-center gap-2 mb-3">
|
|
<span className="w-2 h-2 rounded-full flex-shrink-0" style={{ backgroundColor: color }}></span>
|
|
<h3 className="text-sm font-semibold text-gray-800">{title}</h3>
|
|
<span className="text-xs text-gray-400">{subtitle}</span>
|
|
</div>
|
|
<div className="flex gap-3" style={{ flexWrap: 'wrap' }}>
|
|
<Input label="이름" name={`${prefix}_name`} value={form[`${prefix}_name`]} error={errors[`${prefix}_name`]}
|
|
onChange={onChange} required placeholder="홍길동" style={{ flex: '1 1 140px', minWidth: 120 }} />
|
|
<Input label="이메일" name={`${prefix}_email`} value={form[`${prefix}_email`]} error={errors[`${prefix}_email`]}
|
|
onChange={onChange} type="email" required placeholder="hong@example.com" style={{ flex: '2.5 1 200px', minWidth: 180 }} />
|
|
<Input label="전화번호" name={`${prefix}_phone`} value={form[`${prefix}_phone`]} error={errors[`${prefix}_phone`]}
|
|
onChange={onChange} placeholder="010-1234-5678" style={{ flex: '1 1 140px', minWidth: 120 }} />
|
|
</div>
|
|
</div>
|
|
);
|
|
|
|
const App = () => {
|
|
const [form, setForm] = useState({
|
|
title: '', description: '', sign_order_type: 'counterpart_first', expires_at: '',
|
|
creator_name: '', creator_email: '', creator_phone: '',
|
|
counterpart_name: '', counterpart_email: '', counterpart_phone: '',
|
|
});
|
|
const [file, setFile] = useState(null);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [errors, setErrors] = useState({});
|
|
const [templates, setTemplates] = useState([]);
|
|
const [templateId, setTemplateId] = useState('');
|
|
const [templateCategory, setTemplateCategory] = useState('');
|
|
const [templateSearch, setTemplateSearch] = useState('');
|
|
const fileRef = useRef(null);
|
|
|
|
useEffect(() => {
|
|
fetch('/esign/contracts/templates', { headers: { 'Accept': 'application/json' } })
|
|
.then(r => r.json())
|
|
.then(json => { if (json.success) setTemplates(json.data); })
|
|
.catch(() => {});
|
|
}, []);
|
|
|
|
const handleChange = (key, val) => setForm(f => ({...f, [key]: val}));
|
|
|
|
const fillTestData = () => {
|
|
const pick = arr => arr[Math.floor(Math.random() * arr.length)];
|
|
const lastNames = ['김','이','박','최','정','강','조','윤','장','임'];
|
|
const firstNames = ['민수','서연','지훈','수빈','현우','하은','도윤','예진','준호','소영'];
|
|
const types = ['공급','납품','업무협약','기술이전','유지보수','컨설팅','위탁제조','OEM'];
|
|
const year = new Date().getFullYear();
|
|
const rPhone = () => `010-${String(Math.floor(Math.random()*9000)+1000)}-${String(Math.floor(Math.random()*9000)+1000)}`;
|
|
setForm(f => ({
|
|
...f,
|
|
title: `${year}년 ${pick(types)} 계약서`,
|
|
description: `테스트용 ${pick(types)} 계약 (자동생성)`,
|
|
creator_name: pick(lastNames) + pick(firstNames),
|
|
creator_email: 'awesomemyword@gmail.com',
|
|
creator_phone: rPhone(),
|
|
counterpart_name: pick(lastNames) + pick(firstNames),
|
|
counterpart_email: 'lightone2017@codebridge-x.com',
|
|
counterpart_phone: rPhone(),
|
|
}));
|
|
};
|
|
|
|
const handleSubmit = async (e) => {
|
|
e.preventDefault();
|
|
setSubmitting(true);
|
|
setErrors({});
|
|
|
|
const fd = new FormData();
|
|
Object.entries(form).forEach(([k, v]) => { if (v) fd.append(k, v); });
|
|
if (file) fd.append('file', file);
|
|
|
|
try {
|
|
fd.append('_token', csrfToken);
|
|
fd.append('signers[0][name]', form.creator_name);
|
|
fd.append('signers[0][email]', form.creator_email);
|
|
fd.append('signers[0][phone]', form.creator_phone || '');
|
|
fd.append('signers[0][role]', 'creator');
|
|
fd.append('signers[1][name]', form.counterpart_name);
|
|
fd.append('signers[1][email]', form.counterpart_email);
|
|
fd.append('signers[1][phone]', form.counterpart_phone || '');
|
|
fd.append('signers[1][role]', 'counterpart');
|
|
|
|
const res = await fetch('/esign/contracts/store', {
|
|
method: 'POST',
|
|
headers: { 'Accept': 'application/json', 'X-CSRF-TOKEN': csrfToken },
|
|
body: fd,
|
|
});
|
|
const json = await res.json();
|
|
if (json.success) {
|
|
const url = templateId
|
|
? `/esign/${json.data.id}/fields?template_id=${templateId}`
|
|
: `/esign/${json.data.id}/fields`;
|
|
location.href = url;
|
|
} else {
|
|
setErrors(json.errors || { general: json.message });
|
|
}
|
|
} catch (e) {
|
|
setErrors({ general: '서버 오류가 발생했습니다.' });
|
|
}
|
|
setSubmitting(false);
|
|
};
|
|
|
|
return (
|
|
<div className="p-4 sm:p-6">
|
|
<div className="flex items-center gap-3 mb-6">
|
|
<a href="/esign" className="text-gray-400 hover:text-gray-600 text-lg" hx-boost="false">←</a>
|
|
<h1 className="text-xl font-bold text-gray-900">새 계약 생성</h1>
|
|
{IS_ADMIN && (
|
|
<button type="button" onClick={fillTestData} title="테스트 데이터 자동 입력"
|
|
className="w-8 h-8 flex items-center justify-center rounded-lg text-amber-500 hover:bg-amber-50 hover:text-amber-600 transition-colors">
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
<path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>
|
|
</svg>
|
|
</button>
|
|
)}
|
|
</div>
|
|
|
|
{errors.general && <div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg mb-4 text-sm">{errors.general}</div>}
|
|
|
|
<form onSubmit={handleSubmit} className="space-y-5">
|
|
{/* 계약 정보 */}
|
|
<div className="bg-white rounded-lg border p-5">
|
|
<h2 className="text-base font-semibold text-gray-900 mb-4">계약 정보</h2>
|
|
<div className="space-y-4">
|
|
<Input label="계약 제목" name="title" value={form.title} error={errors.title} onChange={handleChange} required placeholder="예: 2026년 공급 계약서" />
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">설명</label>
|
|
<textarea value={form.description} onChange={e => handleChange('description', e.target.value)}
|
|
placeholder="계약에 대한 간단한 설명 (선택)" rows={2}
|
|
className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none transition-colors" />
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">PDF 파일 {!templateId && <span className="text-red-500">*</span>}</label>
|
|
<input ref={fileRef} type="file" accept=".pdf" onChange={e => setFile(e.target.files[0])} required={!templateId}
|
|
className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm file:mr-3 file:py-1 file:px-3 file:rounded file:border-0 file:bg-blue-50 file:text-blue-700 file:text-sm file:font-medium file:cursor-pointer" />
|
|
{file && <p className="text-xs text-gray-500 mt-1">{file.name} ({(file.size / 1024 / 1024).toFixed(2)} MB)</p>}
|
|
{templateId && !file && <p className="text-xs text-amber-600 mt-1">템플릿 선택 시 PDF 파일은 선택사항입니다. 나중에 업로드할 수 있습니다.</p>}
|
|
</div>
|
|
<div className="flex gap-4" style={{ flexWrap: 'wrap' }}>
|
|
<div style={{ flex: '1 1 200px' }}>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">서명 순서</label>
|
|
<select value={form.sign_order_type} onChange={e => handleChange('sign_order_type', e.target.value)}
|
|
className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none">
|
|
<option value="counterpart_first">상대방 먼저 서명</option>
|
|
<option value="creator_first">작성자 먼저 서명</option>
|
|
</select>
|
|
</div>
|
|
<div style={{ flex: '1 1 200px' }}>
|
|
<Input label="만료일" name="expires_at" value={form.expires_at} error={errors.expires_at} onChange={handleChange} type="datetime-local" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 서명자 정보 */}
|
|
<div className="bg-white rounded-lg border p-5">
|
|
<h2 className="text-base font-semibold text-gray-900 mb-4">서명자 정보</h2>
|
|
<div className="space-y-5">
|
|
<SignerRow prefix="creator" title="작성자 (갑)" subtitle="나" color="#3B82F6"
|
|
form={form} errors={errors} onChange={handleChange} />
|
|
<div className="border-t"></div>
|
|
<SignerRow prefix="counterpart" title="상대방 (을)" subtitle="서명 요청 대상" color="#EF4444"
|
|
form={form} errors={errors} onChange={handleChange} />
|
|
</div>
|
|
</div>
|
|
|
|
{/* 필드 템플릿 (선택) */}
|
|
{templates.length > 0 && (
|
|
<div className="bg-white rounded-lg border p-5">
|
|
<h2 className="text-base font-semibold text-gray-900 mb-1">필드 템플릿</h2>
|
|
<p className="text-xs text-gray-400 mb-3">계약 생성 후 필드 에디터에서 자동으로 적용됩니다 (선택사항)</p>
|
|
|
|
<div className="flex gap-2 mb-3">
|
|
<select value={templateCategory} onChange={e => setTemplateCategory(e.target.value)}
|
|
className="border border-gray-300 rounded-lg px-3 py-1.5 text-sm focus:ring-2 focus:ring-blue-500 outline-none">
|
|
<option value="">전체 카테고리</option>
|
|
{[...new Set(templates.map(t => t.category).filter(Boolean))].sort().map(c =>
|
|
<option key={c} value={c}>{c}</option>
|
|
)}
|
|
</select>
|
|
<input type="text" value={templateSearch} onChange={e => setTemplateSearch(e.target.value)}
|
|
placeholder="검색..." className="border border-gray-300 rounded-lg px-3 py-1.5 text-sm focus:ring-2 focus:ring-blue-500 outline-none flex-1" />
|
|
</div>
|
|
|
|
<div className="space-y-1.5 max-h-[200px] overflow-y-auto">
|
|
<label className={`flex items-center gap-3 p-2.5 rounded-lg border cursor-pointer transition-colors ${!templateId ? 'border-blue-400 bg-blue-50' : 'hover:bg-gray-50'}`}>
|
|
<input type="radio" name="template" checked={!templateId} onChange={() => setTemplateId('')}
|
|
className="text-blue-600 focus:ring-blue-500" />
|
|
<div>
|
|
<span className="text-sm text-gray-700">없음</span>
|
|
<span className="text-xs text-gray-400 ml-1">(수동 배치)</span>
|
|
</div>
|
|
</label>
|
|
{templates
|
|
.filter(t => !templateCategory || t.category === templateCategory)
|
|
.filter(t => !templateSearch || t.name.toLowerCase().includes(templateSearch.toLowerCase()))
|
|
.map(t => (
|
|
<label key={t.id}
|
|
className={`flex items-center gap-3 p-2.5 rounded-lg border cursor-pointer transition-colors ${templateId == t.id ? 'border-blue-400 bg-blue-50' : 'hover:bg-gray-50'}`}>
|
|
<input type="radio" name="template" checked={templateId == t.id} onChange={() => setTemplateId(t.id)}
|
|
className="text-blue-600 focus:ring-blue-500" />
|
|
<div className="flex-1 min-w-0">
|
|
<span className="text-sm text-gray-800">{t.name}</span>
|
|
<div className="flex items-center gap-2 mt-0.5">
|
|
{t.category && <span className="text-[11px] px-1.5 py-0.5 bg-gray-100 text-gray-500 rounded">{t.category}</span>}
|
|
<span className="text-[11px] text-gray-400">필드 {t.items_count ?? t.items?.length ?? 0}개</span>
|
|
<span className="text-[11px] text-gray-400">서명자 {t.signer_count}명</span>
|
|
</div>
|
|
</div>
|
|
</label>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* 버튼 */}
|
|
<div className="flex justify-end gap-3 pt-1">
|
|
<a href="/esign" className="px-5 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 text-sm transition-colors" hx-boost="false">취소</a>
|
|
<button type="submit" disabled={submitting}
|
|
className="px-5 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 text-sm font-medium disabled:opacity-50 transition-colors">
|
|
{submitting ? '생성 중...' : '계약 생성 및 서명 위치 설정'}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
ReactDOM.createRoot(document.getElementById('esign-create-root')).render(<App />);
|
|
</script>
|
|
@endverbatim
|
|
@endpush
|