- Next.js 16 App Router + TypeScript + Tailwind CSS 4 - Prisma/SQLite 기반 공지사항·자료실·관리자·문의/제보 - 네이버 블로그 RSS 최신 글 5개 노출 - OCI 운영 배포 스크립트 및 문서
107 lines
4.3 KiB
TypeScript
107 lines
4.3 KiB
TypeScript
"use client";
|
|
|
|
import { useActionState } from "react";
|
|
import { AlertCircle, Loader2, Send } from "lucide-react";
|
|
|
|
import { submitInquiryAction, type InquiryState } from "@/actions/inquiries";
|
|
|
|
const initialState: InquiryState = {};
|
|
|
|
const inputClass =
|
|
"h-11 w-full rounded-lg border border-slate-200 bg-white px-3.5 text-sm text-slate-800 placeholder:text-slate-400 focus:border-brand-400 focus:outline-none";
|
|
|
|
const labelClass = "mb-1.5 block text-xs font-bold text-slate-600";
|
|
|
|
export function InquiryForm() {
|
|
const [state, formAction, pending] = useActionState(submitInquiryAction, initialState);
|
|
|
|
return (
|
|
<form action={formAction} className="space-y-5">
|
|
{state.error ? (
|
|
<p role="alert" className="flex items-start gap-2 rounded-xl bg-rose-50 px-4 py-3 text-sm font-semibold text-rose-700">
|
|
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0" aria-hidden />
|
|
{state.error}
|
|
</p>
|
|
) : null}
|
|
|
|
<div className="grid gap-4 sm:grid-cols-2">
|
|
<div>
|
|
<label htmlFor="name" className={labelClass}>
|
|
성함 <span className="text-rose-500">*</span>
|
|
</label>
|
|
<input id="name" name="name" required maxLength={50} autoComplete="name" className={inputClass} placeholder="홍길동" />
|
|
</div>
|
|
<div>
|
|
<label htmlFor="phone" className={labelClass}>
|
|
연락처
|
|
</label>
|
|
<input id="phone" name="phone" maxLength={30} autoComplete="tel" className={inputClass} placeholder="010-0000-0000" />
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label htmlFor="email" className={labelClass}>
|
|
이메일 <span className="text-rose-500">*</span>
|
|
</label>
|
|
<input
|
|
id="email"
|
|
name="email"
|
|
type="email"
|
|
required
|
|
maxLength={200}
|
|
autoComplete="email"
|
|
className={inputClass}
|
|
placeholder="example@email.com"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label htmlFor="title" className={labelClass}>
|
|
제목 <span className="text-rose-500">*</span>
|
|
</label>
|
|
<input id="title" name="title" required maxLength={200} className={inputClass} placeholder="문의 또는 제보 제목" />
|
|
</div>
|
|
|
|
<div>
|
|
<label htmlFor="content" className={labelClass}>
|
|
내용 <span className="text-rose-500">*</span>
|
|
</label>
|
|
<textarea
|
|
id="content"
|
|
name="content"
|
|
required
|
|
rows={8}
|
|
maxLength={5000}
|
|
className="w-full resize-y rounded-lg border border-slate-200 bg-white px-3.5 py-3 text-sm leading-7 text-slate-800 placeholder:text-slate-400 focus:border-brand-400 focus:outline-none"
|
|
placeholder="정비가 필요한 위치(동명, 도로명, 건물 주변)와 문제 상황을 구체적으로 적어 주세요."
|
|
/>
|
|
</div>
|
|
|
|
<div className="rounded-xl bg-slate-50 p-4">
|
|
<label htmlFor="consent" className="flex items-start gap-2.5 text-xs leading-6 text-slate-600">
|
|
<input id="consent" name="consent" type="checkbox" required className="mt-1 h-4 w-4 rounded border-slate-300 text-brand-700 focus:ring-brand-400" />
|
|
<span>
|
|
<span className="font-bold text-slate-700">[필수]</span> 문의 접수 및 답변을 위한 개인정보(성함, 이메일, 연락처) 수집·이용에
|
|
동의합니다. 수집된 정보는 문의 처리 목적으로만 사용되며 처리 완료 후 파기됩니다.
|
|
</span>
|
|
</label>
|
|
</div>
|
|
|
|
{/* 허니팟: 화면에는 보이지 않으며 봇이 채우면 접수를 거부합니다. */}
|
|
<div className="hidden" aria-hidden>
|
|
<label htmlFor="website">웹사이트</label>
|
|
<input id="website" name="website" tabIndex={-1} autoComplete="off" />
|
|
</div>
|
|
|
|
<button
|
|
type="submit"
|
|
disabled={pending}
|
|
className="inline-flex w-full items-center justify-center gap-2 rounded-xl bg-brand-900 px-5 py-3.5 text-sm font-bold text-white transition hover:bg-brand-800 disabled:cursor-not-allowed disabled:opacity-60 sm:w-auto sm:px-8"
|
|
>
|
|
{pending ? <Loader2 className="h-4 w-4 animate-spin" aria-hidden /> : <Send className="h-4 w-4" aria-hidden />}
|
|
{pending ? "접수 중…" : "문의 접수하기"}
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|