summaryrefslogtreecommitdiff
path: root/src/common/libs
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/libs')
-rw-r--r--src/common/libs/authenticate.ts22
-rw-r--r--src/common/libs/clsxm.ts6
-rw-r--r--src/common/libs/toast.tsx23
3 files changed, 51 insertions, 0 deletions
diff --git a/src/common/libs/authenticate.ts b/src/common/libs/authenticate.ts
new file mode 100644
index 0000000..48d0314
--- /dev/null
+++ b/src/common/libs/authenticate.ts
@@ -0,0 +1,22 @@
+const authenticate = async ({
+ username,
+ password,
+}: {
+ username: string;
+ password: string;
+}) => {
+ const res = await fetch("/api/authenticate", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ username,
+ password,
+ }),
+ });
+
+ return res;
+};
+
+export default authenticate;
diff --git a/src/common/libs/clsxm.ts b/src/common/libs/clsxm.ts
new file mode 100644
index 0000000..0aeffa4
--- /dev/null
+++ b/src/common/libs/clsxm.ts
@@ -0,0 +1,6 @@
+import clsx, { ClassValue } from "clsx";
+import { twMerge } from "tw-merge";
+
+export default function clsxm(...classes: ClassValue[]) {
+ return twMerge(clsx(...classes));
+}
diff --git a/src/common/libs/toast.tsx b/src/common/libs/toast.tsx
new file mode 100644
index 0000000..2047a27
--- /dev/null
+++ b/src/common/libs/toast.tsx
@@ -0,0 +1,23 @@
+import ReactHotToast, { Toast } from "react-hot-toast"
+import clsxm from "./clsxm"
+import { ReactNode } from "react"
+import { XIcon } from "lucide-react"
+
+type Options = Partial<Pick<Toast, "style" | "className" | "id" | "icon" | "duration" | "ariaProps" | "position" | "iconTheme">> | undefined
+
+const toast = (children: ReactNode, options: Options = undefined) => {
+ return ReactHotToast.custom((t) => (
+ <div className={clsxm("bg-neutral-100 border border-neutral-200 text-neutral-800 text-sm rounded-lg flex", {
+ "animate-appearance-in": t.visible,
+ "animate-appearance-out": !t.visible
+ })}>
+ <span className="py-2 px-3">{children}</span>
+ <div className="w-[1px] h-full bg-neutral-300" />
+ <button type="button" className="px-2 text-neutral-800" onClick={() => ReactHotToast.dismiss(t.id)}>
+ <XIcon size={18} />
+ </button>
+ </div>
+ ), options)
+}
+
+export default toast \ No newline at end of file