-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9862e3
commit ca69f83
Showing
8 changed files
with
221 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
apps/sovoli.com/src/app/(dashboard)/new/actions/newNoteAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use server"; | ||
|
||
import { unauthorized } from "next/navigation"; | ||
import { withZod } from "@rvf/zod"; | ||
import { auth } from "@sovoli/auth"; | ||
|
||
import { formNewNoteSchema } from "./schemas"; | ||
|
||
export type State = { | ||
status: "error"; | ||
message: string; | ||
errors?: Record<string, string>; | ||
} | null; | ||
|
||
const validator = withZod(formNewNoteSchema); | ||
|
||
export async function newNoteAction( | ||
_prevState: State, | ||
formData: FormData, | ||
): Promise<State> { | ||
const session = await auth(); | ||
if (!session) { | ||
unauthorized(); | ||
} | ||
|
||
const result = await validator.validate(formData); | ||
|
||
if (result.error) { | ||
return { | ||
status: "error", | ||
message: "Failed to create note", | ||
errors: result.error.fieldErrors, | ||
}; | ||
} | ||
|
||
throw new Error("Not implemented"); | ||
} |
11 changes: 11 additions & 0 deletions
11
apps/sovoli.com/src/app/(dashboard)/new/actions/schemas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { z } from "zod"; | ||
|
||
/** | ||
* For usage with the form action and form | ||
*/ | ||
export const formNewNoteSchema = z.object({ | ||
title: z.string(), | ||
description: z.string(), | ||
content: z.string(), | ||
}); | ||
export type FormNewNoteSchema = z.infer<typeof formNewNoteSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1 @@ | ||
import * as React from "react"; | ||
import { tv } from "tailwind-variants"; | ||
|
||
// Tailwind Variants for Alert Container | ||
const alertContainer = tv({ | ||
base: "relative w-full rounded-lg border p-4 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7", | ||
variants: { | ||
variant: { | ||
default: "bg-background text-foreground", | ||
danger: | ||
"border-danger/50 text-danger dark:border-danger [&>svg]:text-danger", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
}, | ||
}); | ||
|
||
const alertTitleStyles = tv({ | ||
base: "mb-1 font-medium leading-none tracking-tight", | ||
}); | ||
|
||
const alertDescriptionStyles = tv({ | ||
base: "text-sm [&_p]:leading-relaxed", | ||
}); | ||
|
||
// Alert Component | ||
const Alert = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> & { variant?: "default" | "danger" } | ||
>(({ className, variant = "default", ...props }, ref) => ( | ||
<div | ||
ref={ref} | ||
role="alert" | ||
className={alertContainer({ variant, className })} | ||
{...props} | ||
/> | ||
)); | ||
Alert.displayName = "Alert"; | ||
|
||
// AlertTitle Component | ||
const AlertTitle = React.forwardRef< | ||
HTMLParagraphElement, | ||
React.HTMLAttributes<HTMLHeadingElement> | ||
>(({ className, ...props }, ref) => ( | ||
<h5 ref={ref} className={alertTitleStyles({ className })} {...props} /> | ||
)); | ||
AlertTitle.displayName = "AlertTitle"; | ||
|
||
// AlertDescription Component | ||
const AlertDescription = React.forwardRef< | ||
HTMLParagraphElement, | ||
React.HTMLAttributes<HTMLParagraphElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div ref={ref} className={alertDescriptionStyles({ className })} {...props} /> | ||
)); | ||
AlertDescription.displayName = "AlertDescription"; | ||
|
||
export { Alert, AlertTitle, AlertDescription }; | ||
export * from "@nextui-org/alert"; |
Oops, something went wrong.