mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-26 07:11:09 -05:00
feat: Add button loading states
This commit is contained in:
@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button';
|
||||
import type { RideModelTechnicalSpec } from '@/types/database';
|
||||
import { getErrorMessage } from '@/lib/errorHandler';
|
||||
import { handleError } from '@/lib/errorHandler';
|
||||
import { toast } from 'sonner';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Label } from '@/components/ui/label';
|
||||
@@ -71,6 +72,7 @@ export function RideModelForm({
|
||||
initialData
|
||||
}: RideModelFormProps) {
|
||||
const { isModerator } = useUserRole();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [technicalSpecs, setTechnicalSpecs] = useState<{
|
||||
spec_name: string;
|
||||
spec_value: string;
|
||||
@@ -101,14 +103,16 @@ export function RideModelForm({
|
||||
});
|
||||
|
||||
|
||||
const handleFormSubmit = (data: RideModelFormData) => {
|
||||
const handleFormSubmit = async (data: RideModelFormData) => {
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
// Include relational technical specs with extended type
|
||||
onSubmit({
|
||||
await onSubmit({
|
||||
...data,
|
||||
manufacturer_id: manufacturerId,
|
||||
_technical_specifications: technicalSpecs
|
||||
});
|
||||
toast.success('Ride model submitted for review');
|
||||
} catch (error: unknown) {
|
||||
handleError(error, {
|
||||
action: initialData?.id ? 'Update Ride Model' : 'Create Ride Model'
|
||||
@@ -116,6 +120,8 @@ export function RideModelForm({
|
||||
|
||||
// Re-throw so parent can handle modal closing
|
||||
throw error;
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -294,12 +300,15 @@ export function RideModelForm({
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={onCancel}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
<X className="w-4 h-4 mr-2" />
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
loading={isSubmitting}
|
||||
loadingText="Saving..."
|
||||
>
|
||||
<Save className="w-4 h-4 mr-2" />
|
||||
Save Model
|
||||
|
||||
Reference in New Issue
Block a user