feat: add form validation for keamanan module admin pages
- Added isFormValid() and isHtmlEmpty() helper functions - Disabled submit buttons when required fields are empty - Applied consistent validation pattern across all create/edit pages - Validated fields: judul, deskripsi, lokasi, tanggal, status, kronologi, penanganan, link video, and image uploads - Edit pages allow existing images, create pages require new uploads Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -53,6 +53,21 @@ function EditKeamananLingkungan() {
|
|||||||
imageUrl: "",
|
imageUrl: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Helper function to check if HTML content is empty
|
||||||
|
const isHtmlEmpty = (html: string) => {
|
||||||
|
// Remove all HTML tags and check if there's any text content
|
||||||
|
const textContent = html.replace(/<[^>]*>/g, '').trim();
|
||||||
|
return textContent === '';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
formData.name?.trim() !== '' &&
|
||||||
|
!isHtmlEmpty(formData.deskripsi)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Load data sekali pas mount
|
// Load data sekali pas mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
@@ -294,8 +309,11 @@ function EditKeamananLingkungan() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -35,6 +35,22 @@ function CreateKeamananLingkungan() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
|
|
||||||
|
// Helper function to check if HTML content is empty
|
||||||
|
const isHtmlEmpty = (html: string) => {
|
||||||
|
// Remove all HTML tags and check if there's any text content
|
||||||
|
const textContent = html.replace(/<[^>]*>/g, '').trim();
|
||||||
|
return textContent === '';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
keamananState.create.form.name?.trim() !== '' &&
|
||||||
|
!isHtmlEmpty(keamananState.create.form.deskripsi) &&
|
||||||
|
file !== null
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
keamananState.create.form = {
|
keamananState.create.form = {
|
||||||
name: '',
|
name: '',
|
||||||
@@ -237,8 +253,11 @@ function CreateKeamananLingkungan() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -39,6 +39,15 @@ function EditKontakItem() {
|
|||||||
icon: '',
|
icon: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
formData.name?.trim() !== '' &&
|
||||||
|
formData.nomorTelepon?.trim() !== '' &&
|
||||||
|
formData.icon?.trim() !== ''
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Load data sekali dari global state
|
// Load data sekali dari global state
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadKontakDarurat = async () => {
|
const loadKontakDarurat = async () => {
|
||||||
@@ -170,8 +179,11 @@ function EditKontakItem() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -23,6 +23,16 @@ function CreateKontakItem() {
|
|||||||
const kontakState = useProxy(kontakDarurat.kontakDaruratItem);
|
const kontakState = useProxy(kontakDarurat.kontakDaruratItem);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
kontakState.create.form.nama?.trim() !== '' &&
|
||||||
|
kontakState.create.form.nomorTelepon?.trim() !== '' &&
|
||||||
|
kontakState.create.form.icon?.trim() !== ''
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
kontakState.create.form = {
|
kontakState.create.form = {
|
||||||
nama: '',
|
nama: '',
|
||||||
@@ -115,8 +125,11 @@ function CreateKontakItem() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -46,6 +46,14 @@ export default function EditKontakDaruratKeamanan() {
|
|||||||
kategoriId: [],
|
kategoriId: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
formData.name?.trim() !== '' &&
|
||||||
|
formData.kategoriId.length > 0
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// 🔁 Load data saat ID berubah
|
// 🔁 Load data saat ID berubah
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadInitialData = async () => {
|
const loadInitialData = async () => {
|
||||||
@@ -213,8 +221,11 @@ export default function EditKontakDaruratKeamanan() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -26,6 +26,14 @@ function CreateKontakDaruratKeamanan() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
kontakState.create.form.nama?.trim() !== '' &&
|
||||||
|
kontakState.create.form.icon?.trim() !== ''
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
kontakDarurat.kontakDaruratItem.findMany.load();
|
kontakDarurat.kontakDaruratItem.findMany.load();
|
||||||
}, []);
|
}, []);
|
||||||
@@ -127,8 +135,11 @@ function CreateKontakDaruratKeamanan() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -55,6 +55,25 @@ function EditLaporanPublik() {
|
|||||||
kronologi: '',
|
kronologi: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Helper function to check if HTML content is empty
|
||||||
|
const isHtmlEmpty = (html: string) => {
|
||||||
|
// Remove all HTML tags and check if there's any text content
|
||||||
|
const textContent = html.replace(/<[^>]*>/g, '').trim();
|
||||||
|
return textContent === '';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
formData.judul?.trim() !== '' &&
|
||||||
|
formData.lokasi?.trim() !== '' &&
|
||||||
|
formData.tanggalWaktu?.trim() !== '' &&
|
||||||
|
formData.status?.trim() !== '' &&
|
||||||
|
!isHtmlEmpty(formData.kronologi) &&
|
||||||
|
!isHtmlEmpty(formData.penanganan)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadLaporanPublik = async () => {
|
const loadLaporanPublik = async () => {
|
||||||
const id = params?.id as string;
|
const id = params?.id as string;
|
||||||
@@ -223,8 +242,11 @@ function EditLaporanPublik() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ function CreateLaporanPublik() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
stateLaporan.create.form.judul?.trim() !== '' &&
|
||||||
|
stateLaporan.create.form.lokasi?.trim() !== '' &&
|
||||||
|
stateLaporan.create.form.tanggalWaktu?.trim() !== '' &&
|
||||||
|
stateLaporan.create.form.kronologi?.trim() !== ''
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
stateLaporan.create.form = {
|
stateLaporan.create.form = {
|
||||||
judul: '',
|
judul: '',
|
||||||
@@ -123,8 +133,11 @@ function CreateLaporanPublik() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -41,6 +41,23 @@ function EditPencegahanKriminalitas() {
|
|||||||
linkVideo: '',
|
linkVideo: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Helper function to check if HTML content is empty
|
||||||
|
const isHtmlEmpty = (html: string) => {
|
||||||
|
// Remove all HTML tags and check if there's any text content
|
||||||
|
const textContent = html.replace(/<[^>]*>/g, '').trim();
|
||||||
|
return textContent === '';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
formData.judul?.trim() !== '' &&
|
||||||
|
!isHtmlEmpty(formData.deskripsiSingkat) &&
|
||||||
|
!isHtmlEmpty(formData.deskripsi) &&
|
||||||
|
convertYoutubeUrlToEmbed(formData.linkVideo) !== ''
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// load data hanya sekali pas id berubah
|
// load data hanya sekali pas id berubah
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadKriminalitas = async () => {
|
const loadKriminalitas = async () => {
|
||||||
@@ -220,8 +237,11 @@ function EditPencegahanKriminalitas() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -28,6 +28,23 @@ function CreatePencegahanKriminalitas() {
|
|||||||
const embedLink = convertYoutubeUrlToEmbed(link);
|
const embedLink = convertYoutubeUrlToEmbed(link);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Helper function to check if HTML content is empty
|
||||||
|
const isHtmlEmpty = (html: string) => {
|
||||||
|
// Remove all HTML tags and check if there's any text content
|
||||||
|
const textContent = html.replace(/<[^>]*>/g, '').trim();
|
||||||
|
return textContent === '';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
kriminalitasState.create.form.judul?.trim() !== '' &&
|
||||||
|
!isHtmlEmpty(kriminalitasState.create.form.deskripsiSingkat) &&
|
||||||
|
!isHtmlEmpty(kriminalitasState.create.form.deskripsi) &&
|
||||||
|
embedLink !== ''
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
kriminalitasState.create.form = {
|
kriminalitasState.create.form = {
|
||||||
judul: "",
|
judul: "",
|
||||||
@@ -165,8 +182,11 @@ function CreatePencegahanKriminalitas() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -67,6 +67,17 @@ function EditPolsekTerdekat() {
|
|||||||
layananPolsekId: []
|
layananPolsekId: []
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
formData.nama?.trim() !== '' &&
|
||||||
|
formData.jarakKeDesa?.trim() !== '' &&
|
||||||
|
formData.alamat?.trim() !== '' &&
|
||||||
|
formData.nomorTelepon?.trim() !== '' &&
|
||||||
|
formData.layananPolsekId.length > 0
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
statePolsekTerdekat.layananPolsek.findManyAll.load();
|
statePolsekTerdekat.layananPolsek.findManyAll.load();
|
||||||
}, []);
|
}, []);
|
||||||
@@ -261,8 +272,11 @@ function EditPolsekTerdekat() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -24,6 +24,17 @@ function CreatePolsekTerdekat() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
polsekState.create.form.nama?.trim() !== '' &&
|
||||||
|
polsekState.create.form.jarakKeDesa?.trim() !== '' &&
|
||||||
|
polsekState.create.form.alamat?.trim() !== '' &&
|
||||||
|
polsekState.create.form.nomorTelepon?.trim() !== '' &&
|
||||||
|
polsekState.create.form.layananPolsekId.length > 0
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
statePolsekTerdekat.layananPolsek.findManyAll.load();
|
statePolsekTerdekat.layananPolsek.findManyAll.load();
|
||||||
}, []);
|
}, []);
|
||||||
@@ -219,8 +230,11 @@ function CreatePolsekTerdekat() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ function EditLayananPolsek() {
|
|||||||
nama: '',
|
nama: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return formData.nama?.trim() !== '';
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadLayananPolsek = async () => {
|
const loadLayananPolsek = async () => {
|
||||||
const id = params?.id as string;
|
const id = params?.id as string;
|
||||||
@@ -143,8 +148,11 @@ function EditLayananPolsek() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ function CreateLayananPolsek() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return createState.create.form.nama?.trim() !== '';
|
||||||
|
};
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
createState.create.form = {
|
createState.create.form = {
|
||||||
nama: '',
|
nama: '',
|
||||||
@@ -93,8 +98,11 @@ function CreateLayananPolsek() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -52,6 +52,21 @@ function EditTipsKeamanan() {
|
|||||||
imageUrl: "",
|
imageUrl: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Helper function to check if HTML content is empty
|
||||||
|
const isHtmlEmpty = (html: string) => {
|
||||||
|
// Remove all HTML tags and check if there's any text content
|
||||||
|
const textContent = html.replace(/<[^>]*>/g, '').trim();
|
||||||
|
return textContent === '';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
formData.judul?.trim() !== '' &&
|
||||||
|
!isHtmlEmpty(formData.deskripsi)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Load data saat pertama kali
|
// Load data saat pertama kali
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
@@ -295,8 +310,11 @@ function EditTipsKeamanan() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -30,6 +30,22 @@ function CreateKeamananLingkungan() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Helper function to check if HTML content is empty
|
||||||
|
const isHtmlEmpty = (html: string) => {
|
||||||
|
// Remove all HTML tags and check if there's any text content
|
||||||
|
const textContent = html.replace(/<[^>]*>/g, '').trim();
|
||||||
|
return textContent === '';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if form is valid
|
||||||
|
const isFormValid = () => {
|
||||||
|
return (
|
||||||
|
stateKeamanan.create.form.judul?.trim() !== '' &&
|
||||||
|
!isHtmlEmpty(stateKeamanan.create.form.deskripsi) &&
|
||||||
|
file !== null
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
stateKeamanan.create.form = {
|
stateKeamanan.create.form = {
|
||||||
judul: '',
|
judul: '',
|
||||||
@@ -199,8 +215,11 @@ function CreateKeamananLingkungan() {
|
|||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
radius="md"
|
radius="md"
|
||||||
size="md"
|
size="md"
|
||||||
|
disabled={!isFormValid() || isSubmitting}
|
||||||
style={{
|
style={{
|
||||||
background: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
background: !isFormValid() || isSubmitting
|
||||||
|
? `linear-gradient(135deg, #cccccc, #eeeeee)`
|
||||||
|
: `linear-gradient(135deg, ${colors['blue-button']}, #4facfe)`,
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user