Update NewChatForm.tsx
This commit is contained in:
@@ -179,11 +179,18 @@ export default function NewChatForm() {
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!buyerId || !selectedStore) {
|
||||
toast.error("Please fill all required fields");
|
||||
if (!buyerId) {
|
||||
toast.error("Please select a customer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (vendorStores.length === 0) {
|
||||
toast.error("No store available. Please create a store first.");
|
||||
return;
|
||||
}
|
||||
|
||||
const storeId = vendorStores[0]._id;
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const authAxios = getAuthAxios();
|
||||
@@ -195,7 +202,7 @@ export default function NewChatForm() {
|
||||
|
||||
const response = await authAxios.post("/chats/create", {
|
||||
buyerId,
|
||||
storeId: selectedStore,
|
||||
storeId: storeId,
|
||||
initialMessage: initialMessage.trim() || undefined
|
||||
});
|
||||
|
||||
@@ -305,43 +312,6 @@ export default function NewChatForm() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="store">Store</Label>
|
||||
{vendorStores.length === 0 ? (
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground p-2 border rounded-md">
|
||||
No store available. Please create a store first.
|
||||
</p>
|
||||
</div>
|
||||
) : vendorStores.length === 1 ? (
|
||||
<div className="p-2 border rounded-md bg-muted/20">
|
||||
<p className="text-sm font-medium">
|
||||
{vendorStores[0].name}
|
||||
</p>
|
||||
<input
|
||||
type="hidden"
|
||||
value={vendorStores[0]._id}
|
||||
name="storeId"
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<select
|
||||
id="store"
|
||||
value={selectedStore}
|
||||
onChange={(e) => setSelectedStore(e.target.value)}
|
||||
className="w-full rounded-md border border-input bg-background px-3 py-2"
|
||||
required
|
||||
>
|
||||
<option value="" disabled>Select a store</option>
|
||||
{vendorStores.map((store) => (
|
||||
<option key={store._id} value={store._id}>
|
||||
{store.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="initialMessage">Initial Message (Optional)</Label>
|
||||
<Textarea
|
||||
@@ -362,7 +332,7 @@ export default function NewChatForm() {
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={loading || !buyerId || !selectedStore}>
|
||||
<Button type="submit" disabled={loading || !buyerId || vendorStores.length === 0}>
|
||||
{loading ? (
|
||||
<>
|
||||
<RefreshCw className="mr-2 h-4 w-4 animate-spin" />
|
||||
|
||||
Reference in New Issue
Block a user