update add row whatsapp on manage notification
This commit is contained in:
@ -339,6 +339,17 @@ const AddDialog = () => {
|
|||||||
/>
|
/>
|
||||||
<span>E-Mail</span>
|
<span>E-Mail</span>
|
||||||
</label>
|
</label>
|
||||||
|
<label className="flex items-center space-x-2">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="via"
|
||||||
|
value="whatsapp"
|
||||||
|
checked={formField.via === 'whatsapp'}
|
||||||
|
onChange={handleChange}
|
||||||
|
className="accent-blue-600"
|
||||||
|
/>
|
||||||
|
<span>WhatsApp</span>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{errors.via && (
|
{errors.via && (
|
||||||
@ -350,6 +361,29 @@ const AddDialog = () => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="w-full">
|
||||||
|
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
|
<label className="form-label flex items-center gap-1 max-w-56">
|
||||||
|
Number WhatsApp
|
||||||
|
</label>
|
||||||
|
<Input
|
||||||
|
className="input col-span-6"
|
||||||
|
name="content"
|
||||||
|
placeholder="Enter OTP (5 digits)"
|
||||||
|
value={formField.content}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
if (/^\d{0,5}$/.test(value)) {
|
||||||
|
handleChange(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={formField.via !== 'whatsapp'}
|
||||||
|
inputMode="numeric"
|
||||||
|
pattern="\d*"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label className="form-label flex items-center gap-1 max-w-56">Subject</label>
|
<label className="form-label flex items-center gap-1 max-w-56">Subject</label>
|
||||||
|
|||||||
@ -25,13 +25,13 @@ export const validateFormNotification = (
|
|||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
{ key: 'all_customer', label: 'Send To' },
|
{ key: 'all_customer', label: 'Send To' },
|
||||||
{ key: 'type', label: 'Type' },
|
{ key: 'type', label: 'Type' },
|
||||||
{ key: 'via', label: 'Via' },
|
{ key: 'via', label: 'Via' }
|
||||||
{ key: 'content', label: 'Content' }
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const newErrors: Record<string, string> = {};
|
const newErrors: Record<string, string> = {};
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
|
|
||||||
|
// Validasi field yang wajib secara umum
|
||||||
requiredFields.forEach(({ key, label }) => {
|
requiredFields.forEach(({ key, label }) => {
|
||||||
if (
|
if (
|
||||||
formField[key as keyof typeof formField] === '' ||
|
formField[key as keyof typeof formField] === '' ||
|
||||||
@ -44,6 +44,21 @@ export const validateFormNotification = (
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Validasi khusus content
|
||||||
|
if (formField.via === 'whatsapp') {
|
||||||
|
if (!formField.content || !/^\d{5}$/.test(formField.content)) {
|
||||||
|
newErrors.content = 'Content harus berupa 5 digit angka (OTP)';
|
||||||
|
toast.error('Content harus berupa 5 digit angka (OTP)');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!formField.content || formField.content.trim() === '') {
|
||||||
|
newErrors.content = 'Content is required';
|
||||||
|
toast.error('Content is required');
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setErrors(newErrors);
|
setErrors(newErrors);
|
||||||
return isValid;
|
return isValid;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user