i have react front end and laravel backend insurance claim system,
most is done need help in frontend client (user= drive) make it use backend api
here is model
class GarageReview extends Model
{
protected table=′garagereviews′;publicincrementing = false;
protected keyType=′string′;proprimaryKey = 'id';
protected $casts = [
// 'id' => 'uuid',
// 'garage_id' => 'uuid',
// 'user_id' => 'uuid',
'rating' => 'int'
];
protected $fillable = [
'id',
'garage_id',
'user_id',
'rating',
'comment'
];
public function garage()
{
return $this->belongsTo(Garage::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}
here is is the snippet in notifications page,
{selectedNotification && (
<VehiclePickupDialog
open={isPickupDialogOpen}
onOpenChange={setIsPickupDialogOpen}
onConfirm={handlePickupConfirm}
vehicle={selectedNotification.vehicle}
apiRequest={apiRequest}
tenant_id={user.tenant_id}
/>
)}
{selectedNotification && (
<GarageRatingDialog
open={isRatingDialogOpen}
onOpenChange={setIsRatingDialogOpen}
garage={selectedNotification.garage}
onSubmit={handleRateGarage}
apiRequest={apiRequest}
tenant_id={user.tenant_id}
/>
"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import { Car, CheckCircle2 } from "lucide-react"
const API_URL = process.env.NEXT_PUBLIC_APP_API_URL;
interface VehiclePickupDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
onConfirm: () => void
vehicle: {
make: string
model: string
plateNumber: string
garage: string
},
apiRequest: (url: string, method: string, body?: any) => Promise;
tenant_id: string;
}
export function VehiclePickupDialog({ open, onOpenChange, onConfirm, vehicle,apiRequest,tenant_id }: VehiclePickupDialogProps) {
const [isSubmitting, setIsSubmitting] = useState(false)
const handleConfirm = async () => {
setIsSubmitting(true)
// Simulate API call
await apiRequest(`${API_URL}urlroute/`, "POST", {}) // api request calls backend
setTimeout(() => {
setIsSubmitting(false)
onConfirm()
}, 1000)
}
return (
Confirm Vehicle Pickup
Please confirm that you have received your vehicle and that the repairs are satisfactory.
Vehicle Details
Make:
{vehicle.make}
Model:
{vehicle.model}
Plate Number:
{vehicle.plateNumber}
Garage:
{vehicle.garage}
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
{isSubmitting ? (
"Processing..."
) : (
<>
Confirm Pickup
</>
)}
)
}
"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import { Textarea } from "@/components/ui/textarea"
import { StarRating } from "@/components/star-rating"
import { Building2, ThumbsUp } from "lucide-react"
import { useToast } from "@/components/ui/use-toast"
const API_URL = process.env.NEXT_PUBLIC_APP_API_URL;
interface GarageRatingDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
garage: {
name: string
address: string
},
apiRequest: (url: string, method: string, body?: any) => Promise;
tenant_id: string;
}
export function GarageRatingDialog({ open, onOpenChange, garage, apiRequest,tenant_id }: GarageRatingDialogProps) {
const [rating, setRating] = useState(0)
const [feedback, setFeedback] = useState("")
const [isSubmitting, setIsSubmitting] = useState(false)
const { toast } = useToast()
const handleSubmit = async () => {
if (rating === 0) {
toast({
title: "Rating required",
description: "Please provide a star rating before submitting.",
variant: "destructive",
})
return
}
setIsSubmitting(true)
// Simulate API call
await apiRequest(`${API_URL}urlroute/`, "POST", {}) // api request calls backend
setTimeout(() => {
setIsSubmitting(false)
toast({
title: "Thank you for your feedback!",
description: "Your rating has been submitted successfully.",
})
onOpenChange(false)
// Reset form
setRating(0)
setFeedback("")
}, 1000)
}
return (
Rate Your Garage Experience
Please rate your experience with {garage.name} and provide any feedback.
Garage Rating
Additional Feedback (Optional)
<Textarea
placeholder="Share your experience with the garage..."
value={feedback}
onChange={(e) => setFeedback(e.target.value)}
rows={4}
/>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Skip
{isSubmitting ? (
"Submitting..."
) : (
<>
Submit Rating
</>
)}
)
}