feat: add form validation for ekonomi 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: nama, deskripsi, tahun, jumlah, value, icon, statistik, and more
- Edit pages allow existing data, create pages require all fields

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
2026-02-18 16:13:20 +08:00
parent aa354992e7
commit 1ddc1d7eac
32 changed files with 523 additions and 32 deletions

View File

@@ -53,6 +53,19 @@ function EditDetailDataPengangguran() {
percentageChange: 0,
});
// Check if form is valid
const isFormValid = () => {
return (
formData.month?.trim() !== '' &&
formData.year !== null &&
formData.year > 0 &&
formData.educatedUnemployment !== null &&
formData.educatedUnemployment >= 0 &&
formData.uneducatedUnemployment !== null &&
formData.uneducatedUnemployment >= 0
);
};
// --- hitung total + persentase perubahan
const calculateTotalAndChange = useCallback(
async (data: typeof formData) => {
@@ -255,8 +268,11 @@ function EditDetailDataPengangguran() {
onClick={handleSubmit}
radius="md"
size="md"
disabled={!isFormValid() || isSubmitting}
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',
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
}}

View File

@@ -27,6 +27,19 @@ function CreateJumlahPengangguran() {
const router = useRouter();
const [isSubmitting, setIsSubmitting] = useState(false);
// Check if form is valid
const isFormValid = () => {
return (
stateDetail.create.form.month?.trim() !== '' &&
stateDetail.create.form.year !== null &&
stateDetail.create.form.year > 0 &&
stateDetail.create.form.educatedUnemployment !== null &&
stateDetail.create.form.educatedUnemployment >= 0 &&
stateDetail.create.form.uneducatedUnemployment !== null &&
stateDetail.create.form.uneducatedUnemployment >= 0
);
};
const monthOptions = [
'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun',
'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des'
@@ -204,8 +217,11 @@ function CreateJumlahPengangguran() {
onClick={handleSubmit}
radius="md"
size="md"
disabled={!isFormValid() || isSubmitting}
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',
boxShadow: '0 4px 15px rgba(79, 172, 254, 0.4)',
}}