From 50b2be68ac2200312e29bd2308fda303d4c4401c Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Fri, 7 Aug 2026 08:50:11 +0700 Subject: [PATCH] Add error handling with toast notifications for form submissions - Integrated toast notifications to display error messages when form submissions fail across various components, enhancing user feedback and experience. - Updated components including DeleteUser, FormDialog, ManageTwoFactor, TwoFactorRecoveryCodes, TwoFactorSetupModal, PayrollPeriodShow, EmployeeCreate, EmployeeEdit, CuttingCreate, CuttingEdit, PurchaseCreate, PurchaseEdit, RestockCreate, RestockEdit, TransactionCreate, TransactionEdit, Category management, Product management, Raw Material management, Role management, Settings, and Authentication pages. --- resources/js/components/delete-user.tsx | 5 ++++- resources/js/components/form-dialog.tsx | 18 +++++++++------- resources/js/components/manage-two-factor.tsx | 11 +++++++++- .../components/two-factor-recovery-codes.tsx | 4 ++++ .../js/components/two-factor-setup-modal.tsx | 4 ++++ .../admin/finance/payroll-period/show.tsx | 4 ++++ .../js/pages/admin/hr/employee/create.tsx | 8 ++++++- resources/js/pages/admin/hr/employee/edit.tsx | 4 ++++ .../js/pages/admin/manage/cutting/create.tsx | 3 +++ .../js/pages/admin/manage/cutting/edit.tsx | 3 +++ .../js/pages/admin/manage/purchase/create.tsx | 4 ++++ .../js/pages/admin/manage/purchase/edit.tsx | 4 ++++ .../js/pages/admin/manage/restock/create.tsx | 4 ++++ .../js/pages/admin/manage/restock/edit.tsx | 4 ++++ .../pages/admin/manage/transaction/create.tsx | 4 ++++ .../pages/admin/manage/transaction/edit.tsx | 4 ++++ .../js/pages/admin/master/category/index.tsx | 10 ++++----- .../js/pages/admin/master/product/create.tsx | 4 ++++ .../js/pages/admin/master/product/edit.tsx | 4 ++++ .../admin/master/product/variant/edit.tsx | 4 ++++ .../product/variant/transfer-stock-dialog.tsx | 4 ++++ .../admin/master/raw-material/create.tsx | 4 ++++ .../pages/admin/master/raw-material/edit.tsx | 4 ++++ .../master/raw-material/variant/edit.tsx | 4 ++++ resources/js/pages/admin/roles/create.tsx | 8 ++++++- resources/js/pages/admin/roles/edit.tsx | 8 ++++++- resources/js/pages/admin/settings/index.tsx | 21 ++++++++++++++++++- resources/js/pages/auth/confirm-password.tsx | 9 +++++++- resources/js/pages/auth/forgot-password.tsx | 8 ++++++- resources/js/pages/auth/login.tsx | 4 ++++ resources/js/pages/auth/register.tsx | 4 ++++ resources/js/pages/auth/reset-password.tsx | 4 ++++ .../js/pages/auth/two-factor-challenge.tsx | 4 ++++ resources/js/pages/auth/verify-email.tsx | 9 +++++++- resources/js/pages/settings/profile.tsx | 4 ++++ resources/js/pages/settings/security.tsx | 11 +++------- 36 files changed, 191 insertions(+), 29 deletions(-) diff --git a/resources/js/components/delete-user.tsx b/resources/js/components/delete-user.tsx index 213e76f..f8f960c 100644 --- a/resources/js/components/delete-user.tsx +++ b/resources/js/components/delete-user.tsx @@ -1,5 +1,6 @@ import { Form } from '@inertiajs/react'; import { useRef } from 'react'; +import { toast } from 'sonner'; import ProfileController from '@/actions/App/Http/Controllers/Settings/ProfileController'; import Heading from '@/components/heading'; import InputError from '@/components/input-error'; @@ -59,7 +60,9 @@ export default function DeleteUser() { options={{ preserveScroll: true, }} - onError={() => passwordInput.current?.focus()} + onError={() => { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} resetOnSuccess className="space-y-6" > diff --git a/resources/js/components/form-dialog.tsx b/resources/js/components/form-dialog.tsx index e474904..f10b8a3 100644 --- a/resources/js/components/form-dialog.tsx +++ b/resources/js/components/form-dialog.tsx @@ -1,5 +1,3 @@ -import { Form } from '@inertiajs/react'; -import type { ReactNode } from 'react'; import { Button } from '@/components/ui/button'; import { Dialog, @@ -8,6 +6,9 @@ import { DialogHeader, DialogTitle, } from '@/components/ui/dialog'; +import { Form } from '@inertiajs/react'; +import type { ReactNode } from 'react'; +import { toast } from 'sonner'; type FormDialogProps = { open: boolean; @@ -20,11 +21,11 @@ type FormDialogProps = { submitLabel?: ReactNode; submittingLabel?: ReactNode; children: - | ReactNode - | ((ctx: { - errors: Record; - processing: boolean; - }) => ReactNode); + | ReactNode + | ((ctx: { + errors: Record; + processing: boolean; + }) => ReactNode); }; export function FormDialog({ @@ -46,6 +47,9 @@ export function FormDialog({ action={action} resetOnSuccess={resetOnSuccess} onSuccess={onSuccess} + onError={() => { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} > {({ errors, processing }) => ( <> diff --git a/resources/js/components/manage-two-factor.tsx b/resources/js/components/manage-two-factor.tsx index 84099d3..ad13cd2 100644 --- a/resources/js/components/manage-two-factor.tsx +++ b/resources/js/components/manage-two-factor.tsx @@ -1,6 +1,7 @@ import { Form } from '@inertiajs/react'; import { ShieldCheck } from 'lucide-react'; import { useEffect, useRef, useState } from 'react'; +import { toast } from 'sonner'; import Heading from '@/components/heading'; import TwoFactorRecoveryCodes from '@/components/two-factor-recovery-codes'; import TwoFactorSetupModal from '@/components/two-factor-setup-modal'; @@ -60,7 +61,12 @@ export default function ManageTwoFactor(props: Props) {

-
+ { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} + > {({ processing }) => (
- + { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} + > {({ errors, processing }) => ( <>
diff --git a/resources/js/pages/admin/roles/edit.tsx b/resources/js/pages/admin/roles/edit.tsx index 27eacd0..6ff23ce 100644 --- a/resources/js/pages/admin/roles/edit.tsx +++ b/resources/js/pages/admin/roles/edit.tsx @@ -1,5 +1,6 @@ import { Form, Head, Link } from '@inertiajs/react'; import { ArrowLeft } from 'lucide-react'; +import { toast } from 'sonner'; import InputError from '@/components/input-error'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; @@ -89,7 +90,12 @@ export default function RoleEdit({ role, permissions }: Props) {
- + { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} + > {({ errors, processing }) => ( <>
diff --git a/resources/js/pages/admin/settings/index.tsx b/resources/js/pages/admin/settings/index.tsx index 9017cb8..c3a06cd 100644 --- a/resources/js/pages/admin/settings/index.tsx +++ b/resources/js/pages/admin/settings/index.tsx @@ -1,6 +1,7 @@ import { Form, Head } from '@inertiajs/react'; import { Plus, Trash2 } from 'lucide-react'; import { useState } from 'react'; +import { toast } from 'sonner'; import { FileUpload } from '@/components/file-upload'; import InputError from '@/components/input-error'; import { PhoneNumberInput } from '@/components/phone-number-input'; @@ -94,7 +95,13 @@ function HomepageSettingsTab({ homepage }: HomepageSettingsTabProps) { } return ( - + { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} + > {({ processing, errors }) => (
@@ -522,6 +529,9 @@ export default function AdminSettings({ { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} > {({ processing, errors }) => (
@@ -643,6 +653,9 @@ export default function AdminSettings({ { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} > {({ processing, errors }) => (
@@ -731,6 +744,9 @@ export default function AdminSettings({ { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} > {({ processing }) => (
@@ -790,6 +806,9 @@ export default function AdminSettings({ { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} > {({ processing, errors }) => (
diff --git a/resources/js/pages/auth/confirm-password.tsx b/resources/js/pages/auth/confirm-password.tsx index 0489ce8..df40543 100644 --- a/resources/js/pages/auth/confirm-password.tsx +++ b/resources/js/pages/auth/confirm-password.tsx @@ -1,4 +1,5 @@ import { Form, Head } from '@inertiajs/react'; +import { toast } from 'sonner'; import { index as confirmOptions, store as confirmStore, @@ -26,7 +27,13 @@ export default function ConfirmPassword() { separator="Or confirm with password" /> - + { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} + > {({ processing, errors }) => (
diff --git a/resources/js/pages/auth/forgot-password.tsx b/resources/js/pages/auth/forgot-password.tsx index 25c81b9..49ef047 100644 --- a/resources/js/pages/auth/forgot-password.tsx +++ b/resources/js/pages/auth/forgot-password.tsx @@ -1,5 +1,6 @@ // Components import { Form, Head } from '@inertiajs/react'; +import { toast } from 'sonner'; import { LoaderCircle } from 'lucide-react'; import InputError from '@/components/input-error'; import TextLink from '@/components/text-link'; @@ -21,7 +22,12 @@ export default function ForgotPassword({ status }: { status?: string }) { )}
- + { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} + > {({ processing, errors }) => ( <>
diff --git a/resources/js/pages/auth/login.tsx b/resources/js/pages/auth/login.tsx index cf10840..69b3fb5 100644 --- a/resources/js/pages/auth/login.tsx +++ b/resources/js/pages/auth/login.tsx @@ -1,4 +1,5 @@ import { Form, Head } from '@inertiajs/react'; +import { toast } from 'sonner'; import InputError from '@/components/input-error'; import PasswordInput from '@/components/password-input'; import { Button } from '@/components/ui/button'; @@ -17,6 +18,9 @@ export default function Login() { action={store()} resetOnSuccess={['password']} className="flex flex-col gap-6" + onError={() => { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} > {({ processing, errors }) => ( <> diff --git a/resources/js/pages/auth/register.tsx b/resources/js/pages/auth/register.tsx index ce766ef..b165b69 100644 --- a/resources/js/pages/auth/register.tsx +++ b/resources/js/pages/auth/register.tsx @@ -1,4 +1,5 @@ import { Form, Head } from '@inertiajs/react'; +import { toast } from 'sonner'; import InputError from '@/components/input-error'; import PasswordInput from '@/components/password-input'; import TextLink from '@/components/text-link'; @@ -22,6 +23,9 @@ export default function Register({ passwordRules }: Props) { resetOnSuccess={['password', 'password_confirmation']} disableWhileProcessing className="flex flex-col gap-6" + onError={() => { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} > {({ processing, errors }) => ( <> diff --git a/resources/js/pages/auth/reset-password.tsx b/resources/js/pages/auth/reset-password.tsx index 8b762c3..6fa23dd 100644 --- a/resources/js/pages/auth/reset-password.tsx +++ b/resources/js/pages/auth/reset-password.tsx @@ -1,4 +1,5 @@ import { Form, Head } from '@inertiajs/react'; +import { toast } from 'sonner'; import InputError from '@/components/input-error'; import PasswordInput from '@/components/password-input'; import { Button } from '@/components/ui/button'; @@ -22,6 +23,9 @@ export default function ResetPassword({ token, email, passwordRules }: Props) { {...update.form()} transform={(data) => ({ ...data, token, email })} resetOnSuccess={['password', 'password_confirmation']} + onError={() => { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} > {({ processing, errors }) => (
diff --git a/resources/js/pages/auth/two-factor-challenge.tsx b/resources/js/pages/auth/two-factor-challenge.tsx index 3cddec3..a41ddcc 100644 --- a/resources/js/pages/auth/two-factor-challenge.tsx +++ b/resources/js/pages/auth/two-factor-challenge.tsx @@ -1,6 +1,7 @@ import { Form, Head, setLayoutProps } from '@inertiajs/react'; import { REGEXP_ONLY_DIGITS } from 'input-otp'; import { useMemo, useState } from 'react'; +import { toast } from 'sonner'; import InputError from '@/components/input-error'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; @@ -59,6 +60,9 @@ export default function TwoFactorChallenge() { className="space-y-4" resetOnError resetOnSuccess={!showRecoveryInput} + onError={() => { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} > {({ errors, processing, clearErrors }) => ( <> diff --git a/resources/js/pages/auth/verify-email.tsx b/resources/js/pages/auth/verify-email.tsx index a6fee14..5b1aa16 100644 --- a/resources/js/pages/auth/verify-email.tsx +++ b/resources/js/pages/auth/verify-email.tsx @@ -1,5 +1,6 @@ // Components import { Form, Head } from '@inertiajs/react'; +import { toast } from 'sonner'; import TextLink from '@/components/text-link'; import { Button } from '@/components/ui/button'; import { Spinner } from '@/components/ui/spinner'; @@ -18,7 +19,13 @@ export default function VerifyEmail({ status }: { status?: string }) {
)} - + { + toast.error('Terjadi kesalahan saat menyimpan data. Silakan periksa kembali input Anda.'); + }} + > {({ processing }) => ( <>