Add title field to EmailTemplate model and update UI
This commit is contained in:
@ -6,6 +6,7 @@ import Link from 'next/link';
|
||||
|
||||
interface EmailTemplate {
|
||||
id: string;
|
||||
title: string;
|
||||
content: string;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
@ -18,6 +19,7 @@ interface EditEmailTemplateProps {
|
||||
export default function EditEmailTemplate({ id }: EditEmailTemplateProps) {
|
||||
const router = useRouter();
|
||||
const [formData, setFormData] = useState({
|
||||
title: '',
|
||||
content: '',
|
||||
});
|
||||
const [isLoading, setIsLoading] = useState(!!id); // Only loading if editing
|
||||
@ -42,6 +44,7 @@ export default function EditEmailTemplate({ id }: EditEmailTemplateProps) {
|
||||
const template: EmailTemplate = await response.json();
|
||||
|
||||
setFormData({
|
||||
title: template.title,
|
||||
content: template.content,
|
||||
});
|
||||
|
||||
@ -55,7 +58,7 @@ export default function EditEmailTemplate({ id }: EditEmailTemplateProps) {
|
||||
fetchEmailTemplate();
|
||||
}, [id]);
|
||||
|
||||
const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const handleChange = (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData((prev) => ({ ...prev, [name]: value }));
|
||||
};
|
||||
@ -67,8 +70,8 @@ export default function EditEmailTemplate({ id }: EditEmailTemplateProps) {
|
||||
|
||||
try {
|
||||
// Validate form
|
||||
if (!formData.content) {
|
||||
throw new Error('Content is required');
|
||||
if (!formData.title || !formData.content) {
|
||||
throw new Error('Title and content are required');
|
||||
}
|
||||
|
||||
// Determine if creating or updating
|
||||
@ -132,6 +135,22 @@ export default function EditEmailTemplate({ id }: EditEmailTemplateProps) {
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit} className="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
|
||||
<div className="mb-4">
|
||||
<label className="block text-gray-700 text-sm font-bold mb-2" htmlFor="title">
|
||||
Title
|
||||
</label>
|
||||
<input
|
||||
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
|
||||
id="title"
|
||||
type="text"
|
||||
name="title"
|
||||
value={formData.title}
|
||||
onChange={handleChange}
|
||||
placeholder="Email template title"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mb-6">
|
||||
<label className="block text-gray-700 text-sm font-bold mb-2" htmlFor="content">
|
||||
Content
|
||||
|
||||
Reference in New Issue
Block a user