feat: expand inquiry fields and list
This commit is contained in:
1 parent
4d1aba4888
commit
3fdec5a549
18 files changed
+87
-52
No files matched your search
+38
-1
@@ -22,6 +22,8 @@ type InquiryField = {
|
||||
label: string;
|
||||
fieldType: string;
|
||||
placeholder?: string;
|
||||
helpText?: string;
|
||||
maxLength?: number;
|
||||
required: boolean;
|
||||
optionsJson?: string;
|
||||
widthType: string;
|
||||
@@ -353,12 +355,30 @@ function InquiryForm({
|
||||
});
|
||||
const [custom, setCustom] = useState<Record<string, string>>({});
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [uploadingField, setUploadingField] = useState("");
|
||||
const [notice, setNotice] = useState("");
|
||||
useEffect(() => {
|
||||
post("/inquiries/form-detail", { scene })
|
||||
.then(setDefinition)
|
||||
.catch((e) => setNotice(e.message));
|
||||
}, [scene]);
|
||||
const uploadImage = async (fieldCode: string, file?: File) => {
|
||||
if (!file) return;
|
||||
try {
|
||||
setUploadingField(fieldCode);
|
||||
setNotice("");
|
||||
const body = new FormData();
|
||||
body.append("file", file);
|
||||
const response = await fetch(`${API}/inquiries/upload-image`, { method: "POST", body });
|
||||
if (!response.ok) throw new Error((await response.json()).message || "Unable to upload image");
|
||||
const result = await response.json();
|
||||
setCustom((values) => ({ ...values, [fieldCode]: result.url }));
|
||||
} catch (error) {
|
||||
setNotice(error instanceof Error ? error.message : "Unable to upload image");
|
||||
} finally {
|
||||
setUploadingField("");
|
||||
}
|
||||
};
|
||||
const submit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!definition) return;
|
||||
@@ -438,9 +458,24 @@ function InquiryForm({
|
||||
{field.label}
|
||||
{field.required ? " *" : ""}
|
||||
</span>
|
||||
{field.fieldType === "TEXTAREA" ? (
|
||||
{field.fieldType === "IMAGE" ? (
|
||||
<div className="inquiry-image-field">
|
||||
<input
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp,image/gif"
|
||||
required={field.required && !custom[field.fieldCode]}
|
||||
onChange={(event) => void uploadImage(field.fieldCode, event.target.files?.[0])}
|
||||
/>
|
||||
{uploadingField === field.fieldCode && <small>Uploading…</small>}
|
||||
{custom[field.fieldCode] && (
|
||||
<img src={`http://localhost:8082${custom[field.fieldCode]}`} alt={field.label}/>
|
||||
)}
|
||||
</div>
|
||||
) : field.fieldType === "TEXTAREA" ? (
|
||||
<textarea
|
||||
required={field.required}
|
||||
maxLength={field.maxLength}
|
||||
placeholder={field.placeholder}
|
||||
value={custom[field.fieldCode] || ""}
|
||||
onChange={(e) =>
|
||||
setCustom({ ...custom, [field.fieldCode]: e.target.value })
|
||||
@@ -449,6 +484,7 @@ function InquiryForm({
|
||||
) : (
|
||||
<input
|
||||
required={field.required}
|
||||
maxLength={field.maxLength}
|
||||
placeholder={field.placeholder}
|
||||
value={custom[field.fieldCode] || ""}
|
||||
onChange={(e) =>
|
||||
@@ -456,6 +492,7 @@ function InquiryForm({
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{field.helpText && <small>{field.helpText}</small>}
|
||||
</label>
|
||||
))}
|
||||
<label className="wide">
|
||||
|
||||
@@ -380,6 +380,7 @@ footer small {
|
||||
.inquiry-box label { display: grid; gap: 6px; }
|
||||
.inquiry-box label > span { font-size: 12px; font-weight: 700; }
|
||||
.inquiry-box input, .inquiry-box textarea { width: 100%; border: 1px solid #cbd5d1; background: #fff; padding: 11px 12px; font: inherit; }
|
||||
.inquiry-image-field{display:grid;gap:8px}.inquiry-image-field img{width:160px;height:110px;object-fit:cover;border:1px solid #cbd5d1}.inquiry-image-field small,.inquiry-box label>small{color:#687671;font-size:12px}
|
||||
.inquiry-box .wide { grid-column: 1 / -1; }
|
||||
.consent { display: flex !important; align-items: flex-start; }
|
||||
.consent input { width: auto; margin-top: 4px; }
|
||||
|
||||
Reference in new issue
Block a user