mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-28 23:06:58 -05:00
Enhance FormFieldWrapper with blur validation and toasts
Adds validation on blur mode to FormFieldWrapper, introduces animated validation states, and implements standardized form submission toasts via a new formToasts helper; updates ParkForm and RideForm to use the new toast system and to propagate error state with scroll-to-error support.
This commit is contained in:
65
src/lib/formToasts.ts
Normal file
65
src/lib/formToasts.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
|
||||
/**
|
||||
* Standardized toast notifications for form submissions
|
||||
* Provides consistent success/error feedback across all forms
|
||||
*/
|
||||
export const formToasts = {
|
||||
success: {
|
||||
create: (entityType: string, entityName?: string) => {
|
||||
toast({
|
||||
title: '✓ Submission Created',
|
||||
description: entityName
|
||||
? `${entityName} has been submitted for review.`
|
||||
: `${entityType} has been submitted for review.`,
|
||||
variant: 'default',
|
||||
});
|
||||
},
|
||||
|
||||
update: (entityType: string, entityName?: string) => {
|
||||
toast({
|
||||
title: '✓ Update Submitted',
|
||||
description: entityName
|
||||
? `Changes to ${entityName} have been submitted for review.`
|
||||
: `${entityType} update has been submitted for review.`,
|
||||
variant: 'default',
|
||||
});
|
||||
},
|
||||
|
||||
moderatorApproval: (entityType: string, entityName?: string) => {
|
||||
toast({
|
||||
title: '✓ Published Successfully',
|
||||
description: entityName
|
||||
? `${entityName} is now live on the site.`
|
||||
: `${entityType} is now live on the site.`,
|
||||
variant: 'default',
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
error: {
|
||||
validation: (fieldCount: number) => {
|
||||
toast({
|
||||
title: 'Validation Failed',
|
||||
description: `Please fix ${fieldCount} error${fieldCount > 1 ? 's' : ''} before submitting.`,
|
||||
variant: 'destructive',
|
||||
});
|
||||
},
|
||||
|
||||
network: () => {
|
||||
toast({
|
||||
title: 'Connection Error',
|
||||
description: 'Unable to submit. Please check your connection and try again.',
|
||||
variant: 'destructive',
|
||||
});
|
||||
},
|
||||
|
||||
generic: (error: string) => {
|
||||
toast({
|
||||
title: 'Submission Failed',
|
||||
description: error,
|
||||
variant: 'destructive',
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user