Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

1.1 KB
Raw Blame
import { toast } from "sonner";
import type { ActionResult } from "@/models/action.model";

export function toastSuccess(message: string, title?: string) {
  if (title) toast.success(title, { description: message });
  else toast.success(message);
}

export function toastError(message?: string, title?: string) {
  const text = message ?? "Something went wrong. Please try again.";
  if (title) toast.error(title, { description: text });
  else toast.error(text);
}

// For outcomes that are neither: a deliberate interruption is not an error.
export function toastInfo(message: string, title?: string) {
  if (title) toast.info(title, { description: message });
  else toast.info(message);
}

// Collapses the repeated success/error branch into one call.
export function toastActionResult<T>(
  result: ActionResult<T> | undefined,
  opts: { success: string; onSuccess?: (data: T | undefined) => void; error?: string },
) {
  if (result?.success) {
    toastSuccess(opts.success);
    opts.onSuccess?.(result.data);
  } else {
    toastError(result?.message ?? opts.error);
  }
}