feat(clients): refresh clients page layout and toast feedback

This commit is contained in:
2026-04-28 21:53:26 +03:30
parent 2b5ee2abf1
commit 36a8c0e24c
6 changed files with 207 additions and 166 deletions

View File

@@ -1,5 +1,6 @@
import { useState } from "react";
import { createClient } from "../api/clients";
import { useState } from "react";
import { toast } from "sonner";
import { createClient } from "../api/clients";
import { useTranslation } from "../hooks/useTranslation";
import { Button } from "./ui/button";
import { Input } from "./ui/input";
@@ -22,18 +23,20 @@ export default function CreateClientModal({ isOpen, onClose, onSuccess, workspac
const handleSubmit = async () => {
if (!name.trim()) return;
setIsLoading(true);
try {
await createClient(workspaceId, { name, notes });
onSuccess();
setName("");
setNotes("");
onClose();
} catch (error) {
console.error(t.clients.errors.createFailed, error);
} finally {
setIsLoading(false);
}
};
try {
await createClient(workspaceId, { name, notes });
toast.success(t.clients.createSuccess);
onSuccess();
setName("");
setNotes("");
onClose();
} catch (error) {
console.error(t.clients.errors.createFailed, error);
toast.error(t.clients.errors.createFailed);
} finally {
setIsLoading(false);
}
};
const footer = (
<>
@@ -72,4 +75,4 @@ export default function CreateClientModal({ isOpen, onClose, onSuccess, workspac
</div>
</Modal>
);
}
}

View File

@@ -1,5 +1,6 @@
import { useState } from "react";
import { type Client } from "../types/client";
import { useState } from "react";
import { toast } from "sonner";
import { type Client } from "../types/client";
import { deleteClient } from "../api/clients";
import { useTranslation } from "../hooks/useTranslation";
import { Button } from "./ui/button";
@@ -19,16 +20,18 @@ export default function DeleteClientModal({ isOpen, onClose, onSuccess, client }
const handleDelete = async () => {
if (!client) return;
setIsLoading(true);
try {
await deleteClient(client.id);
onSuccess();
onClose();
} catch (error) {
console.error(t.clients.errors.deleteFailed, error);
} finally {
setIsLoading(false);
}
};
try {
await deleteClient(client.id);
toast.success(t.clients.deleteSuccess);
onSuccess();
onClose();
} catch (error) {
console.error(t.clients.errors.deleteFailed, error);
toast.error(t.clients.errors.deleteFailed);
} finally {
setIsLoading(false);
}
};
const footer = (
<>

View File

@@ -1,5 +1,6 @@
import { useState, useEffect } from "react";
import { type Client } from "../types/client";
import { useState, useEffect } from "react";
import { toast } from "sonner";
import { type Client } from "../types/client";
import { updateClient } from "../api/clients";
import { useTranslation } from "../hooks/useTranslation";
import { Button } from "./ui/button";
@@ -30,16 +31,18 @@ export default function EditClientModal({ isOpen, onClose, onSuccess, client }:
const handleSubmit = async () => {
if (!client || !name.trim()) return;
setIsLoading(true);
try {
await updateClient(client.id, { name, notes });
onSuccess();
onClose();
} catch (error) {
console.error(t.clients.errors.updateFailed, error);
} finally {
setIsLoading(false);
}
};
try {
await updateClient(client.id, { name, notes });
toast.success(t.clients.updateSuccess);
onSuccess();
onClose();
} catch (error) {
console.error(t.clients.errors.updateFailed, error);
toast.error(t.clients.errors.updateFailed);
} finally {
setIsLoading(false);
}
};
const footer = (
<>
@@ -78,4 +81,4 @@ export default function EditClientModal({ isOpen, onClose, onSuccess, client }:
</div>
</Modal>
);
}
}