mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
made it cleaner
This commit is contained in:
parent
84413674c7
commit
3a3de0943b
2 changed files with 55 additions and 89 deletions
|
|
@ -30,13 +30,9 @@ export default function BookSurveyModal({
|
|||
address,
|
||||
onSuccess, // ✅ fix: remove “?:” here, we already declared it optional in interface
|
||||
}: BookSurveyModalProps) {
|
||||
const [formData, setFormData] = useState({
|
||||
dealname: "",
|
||||
});
|
||||
|
||||
// 🧠 Simple mutation to call your HubSpot API
|
||||
const bookSurveyMutation = useMutation({
|
||||
mutationFn: async (data: typeof formData) => {
|
||||
mutationFn: async () => {
|
||||
const res = await fetch("/api/book-survey", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
|
|
@ -63,53 +59,20 @@ export default function BookSurveyModal({
|
|||
},
|
||||
});
|
||||
|
||||
// ✏️ Handle input
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData((prev) => ({ ...prev, [name]: value }));
|
||||
};
|
||||
|
||||
// 🚀 Submit
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
bookSurveyMutation.mutate(formData);
|
||||
bookSurveyMutation.mutate();
|
||||
};
|
||||
|
||||
// 🔁 Reset when modal closes
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
setFormData({ dealname: ""});
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create HubSpot Deal (Test)</DialogTitle>
|
||||
<DialogTitle>Confirm Booking a Survey</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{/* Deal Name */}
|
||||
<div>
|
||||
<Label htmlFor="dealname">Deal Name</Label>
|
||||
<Input
|
||||
id="dealname"
|
||||
name="dealname"
|
||||
value={formData.dealname}
|
||||
onChange={handleChange}
|
||||
placeholder="Enter deal name"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Error Message */}
|
||||
{bookSurveyMutation.isError && (
|
||||
<p className="text-sm text-red-500">
|
||||
{(bookSurveyMutation.error as Error).message}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="submit"
|
||||
|
|
|
|||
|
|
@ -221,6 +221,7 @@ export const columns: ColumnDef<PropertyWithRelations>[] = [
|
|||
const [openModal, setOpenModal] = useState(false);
|
||||
const [showToast, setShowToast] = useState(false);
|
||||
const property = row.original;
|
||||
const address = String(row.getValue("address"));
|
||||
const propertyId = property.id;
|
||||
const portfolioId = property.portfolioId;
|
||||
|
||||
|
|
@ -234,57 +235,59 @@ export const columns: ColumnDef<PropertyWithRelations>[] = [
|
|||
}
|
||||
|
||||
return (
|
||||
<div className="flex justify-center">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||
<DropdownMenuItem onClick={()=> setOpenModal(true)}>
|
||||
Book a survey
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
// onClick={() => navigator.clipboard.writeText(payment.id)}
|
||||
className="text-gray-700 cursor-pointer"
|
||||
>
|
||||
<a href={`${portfolioId}/building-passport/${propertyId}`}>
|
||||
Building Passport
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
<>
|
||||
<div className="flex justify-center">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||
<DropdownMenuItem onClick={()=> setOpenModal(true)}>
|
||||
Book a survey
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
// onClick={() => navigator.clipboard.writeText(payment.id)}
|
||||
className="text-gray-700 cursor-pointer"
|
||||
>
|
||||
<a href={`${portfolioId}/building-passport/${propertyId}`}>
|
||||
Building Passport
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem className="text-gray-700 cursor-pointer">
|
||||
Settings
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-red-500 focus:text-red-700 cursor-pointer">
|
||||
Delete Property
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
{/* ✅ Render modal outside dropdown context */}
|
||||
{openModal && (
|
||||
<BookSurveyModal
|
||||
open={openModal}
|
||||
onOpenChange={setOpenModal}
|
||||
propertyId={propertyId}
|
||||
portfolioId={portfolioId}
|
||||
address={"ask khalim"}
|
||||
onSuccess={() => setShowToast(true)}
|
||||
<DropdownMenuItem className="text-gray-700 cursor-pointer">
|
||||
Settings
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-red-500 focus:text-red-700 cursor-pointer">
|
||||
Delete Property
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
{/* ✅ Render modal outside dropdown context */}
|
||||
{openModal && (
|
||||
<BookSurveyModal
|
||||
open={openModal}
|
||||
onOpenChange={setOpenModal}
|
||||
propertyId={propertyId}
|
||||
portfolioId={portfolioId}
|
||||
address={address}
|
||||
onSuccess={() => setShowToast(true)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 💥 Toast */}
|
||||
<BookingSuccessToast
|
||||
show={showToast}
|
||||
onClose={() => setShowToast(false)}
|
||||
message="Survey Booked Successfully!"
|
||||
subtext="Your Survey Request is with Domna and will be in contact with you shortly. 🎉"
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 💥 Toast */}
|
||||
<BookingSuccessToast
|
||||
show={showToast}
|
||||
onClose={() => setShowToast(false)}
|
||||
message="Deal Created Successfully!"
|
||||
subtext="Your HubSpot deal is ready. 🎉"
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue