Skip to content

Commit

Permalink
Add Sonner for success toast
Browse files Browse the repository at this point in the history
  • Loading branch information
JaaskelainenL committed Jan 15, 2025
1 parent 534df5d commit ae00f6d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 197 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"remeda": "^2.19.0",
"server-only": "^0.0.1",
"sharp": "^0.33.5",
"sonner": "^1.5.0",
"strip-markdown": "^6.0.0",
"tailwind-merge": "catalog:",
"tailwindcss": "catalog:",
Expand Down
15 changes: 8 additions & 7 deletions apps/web/src/components/invoice-generator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
import { SaveAction } from "../../lib/api/external/laskugeneraattori/actions";
import { type InvoiceGeneratorFormState } from "../../lib/api/external/laskugeneraattori/index";

Check warning on line 21 in apps/web/src/components/invoice-generator/index.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Check types & Build

There should be no empty line between import groups

import { Toaster, toast } from "sonner";

Check warning on line 23 in apps/web/src/components/invoice-generator/index.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Check types & Build

`sonner` import should occur before import of `../../locales/client`

interface GenericFieldProps extends InputHTMLAttributes<HTMLInputElement> {
label: string;
unit?: string;
Expand Down Expand Up @@ -86,19 +88,18 @@ function SubmitButton({
const t = useScopedI18n("invoicegenerator");
const { pending } = useFormStatus();
const errorKeys = formState?.errors ? Object.keys(formState.errors) : [];

useEffect(() => {
if (formState?.success === true) toast.success(t("Sent invoice"));
}, [formState]);

Check warning on line 94 in apps/web/src/components/invoice-generator/index.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Check types & Build

React Hook useEffect has a missing dependency: 't'. Either include it or remove the dependency array

return (
<div>
<Button className="w-full max-w-sm" type="submit" disabled={pending}>
{t("Submit")}
</Button>
{formState?.success ? (
<p
data-form-status
className="text-2l w-full max-w-sm text-green-600"
aria-live="polite"
>
{t("Sent invoice")}
</p>
<Toaster richColors />
) : formState?.success === false && errorKeys.length === 0 ? (
<p data-form-status aria-live="polite" className="block text-red-600">
{formState.errorText}
Expand Down
Loading

0 comments on commit ae00f6d

Please sign in to comment.