fix(web): wire up inquiry modal toast notification on listing detail page

The "Nhắn tin" button's inquiry modal now shows a success toast via
sonner after submission instead of an in-dialog success state, and
closes the modal automatically. Added sonner as a dependency and
mounted <Toaster> in the root locale layout.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-16 10:56:56 +07:00
parent 25f415f3bc
commit 44533a88f4
4 changed files with 22 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
'use client';
import * as React from 'react';
import { toast } from 'sonner';
import { Button } from '@/components/ui/button';
import {
Dialog,
@@ -38,7 +39,6 @@ export function InquiryModal({
const [message, setMessage] = React.useState('');
const [phone, setPhone] = React.useState('');
const [error, setError] = React.useState<string | null>(null);
const [success, setSuccess] = React.useState(false);
// Pre-fill phone from auth store when modal opens
React.useEffect(() => {
@@ -47,7 +47,6 @@ export function InquiryModal({
}
if (open) {
setError(null);
setSuccess(false);
setMessage('');
}
}, [open, user?.phone]);
@@ -81,7 +80,10 @@ export function InquiryModal({
message: trimmedMessage,
phone: trimmedPhone,
});
setSuccess(true);
onOpenChange(false);
toast.success('Đã gửi thành công!', {
description: `Tin nhắn của bạn đã được gửi đến ${sellerName}. Họ sẽ liên hệ với bạn sớm nhất có thể.`,
});
} catch (err) {
if (err instanceof ApiError && err.status === 401) {
window.location.href = '/login';
@@ -96,39 +98,6 @@ export function InquiryModal({
}
};
if (success) {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Đã gửi thành công!</DialogTitle>
<DialogDescription>
Tin nhắn của bạn đã đưc gửi đến {sellerName}. Họ sẽ liên hệ với bạn sớm nhất thể.
</DialogDescription>
</DialogHeader>
<div className="flex justify-center py-4">
<svg
className="h-16 w-16 text-green-500"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
</div>
<DialogFooter>
<Button onClick={() => onOpenChange(false)}>Đóng</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>