Updated forms

This commit is contained in:
2025-06-28 00:21:10 +02:00
parent 4ac986745d
commit 7bd43b8e3f
4 changed files with 18 additions and 11 deletions

View File

@@ -53,7 +53,7 @@ function AdvancedUrlForm() {
name="url" name="url"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>Original URL</FormLabel> <FormLabel required>Original URL</FormLabel>
<FormControl> <FormControl>
<Input placeholder="https://example.com" {...field} /> <Input placeholder="https://example.com" {...field} />
</FormControl> </FormControl>
@@ -69,7 +69,7 @@ function AdvancedUrlForm() {
name="slug" name="slug"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>Custom Slug (Optional)</FormLabel> <FormLabel>Custom Slug</FormLabel>
<FormControl> <FormControl>
<Input placeholder="my-custom-link" {...field} value={field.value ?? ""} /> <Input placeholder="my-custom-link" {...field} value={field.value ?? ""} />
</FormControl> </FormControl>
@@ -117,7 +117,7 @@ function AdvancedUrlForm() {
</div> </div>
<FormControl> <FormControl>
<Switch <Switch
checked={field.value ?? false} checked={field.value}
onCheckedChange={field.onChange} onCheckedChange={field.onChange}
/> />
</FormControl> </FormControl>
@@ -131,7 +131,7 @@ function AdvancedUrlForm() {
name="title" name="title"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>Title (Optional)</FormLabel> <FormLabel>Title</FormLabel>
<FormControl> <FormControl>
<Input placeholder="My Link Title" {...field} value={field.value ?? ""} /> <Input placeholder="My Link Title" {...field} value={field.value ?? ""} />
</FormControl> </FormControl>
@@ -147,7 +147,7 @@ function AdvancedUrlForm() {
name="maxVisits" name="maxVisits"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>Max Visits (Optional)</FormLabel> <FormLabel>Max Visits</FormLabel>
<FormControl> <FormControl>
<Input <Input
type="number" type="number"
@@ -174,7 +174,7 @@ function AdvancedUrlForm() {
name="expDate" name="expDate"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>Expiration Date (Optional)</FormLabel> <FormLabel>Expiration Date</FormLabel>
<FormControl> <FormControl>
<DatePicker <DatePicker
value={field.value} value={field.value}

View File

@@ -81,8 +81,12 @@ function FormItem({ className, ...props }: React.ComponentProps<"div">) {
function FormLabel({ function FormLabel({
className, className,
required,
children,
...props ...props
}: React.ComponentProps<typeof LabelPrimitive.Root>) { }: React.ComponentProps<typeof LabelPrimitive.Root> & {
required?: boolean
}) {
const { error, formItemId } = useFormField() const { error, formItemId } = useFormField()
return ( return (
@@ -92,7 +96,10 @@ function FormLabel({
className={cn("data-[error=true]:text-destructive", className)} className={cn("data-[error=true]:text-destructive", className)}
htmlFor={formItemId} htmlFor={formItemId}
{...props} {...props}
/> >
{children}
{required && <span className="text-destructive">*</span>}
</Label>
) )
} }

View File

@@ -66,9 +66,9 @@ export async function createAdvanceUrl(unsafeData: unknown): Promise<Response> {
await insertUrl({ await insertUrl({
...data, ...data,
slug: data.slug?.length === 0 ? undefined : data.slug, slug: data.slug ? data.slug.trim() : undefined,
title: data.title?.length === 0 ? await getWebsiteTitle(data.url) : data.title, title: data.title?.length === 0 ? await getWebsiteTitle(data.url) : data.title,
maxVisits: data.maxVisits > 0 ? data.maxVisits : undefined maxVisits: data.maxVisits ? data.maxVisits : null,
}) })
return { return {

View File

@@ -17,7 +17,7 @@ export const advancedUrlSchema = z.object({
export const editUrlSchema = z.object({ export const editUrlSchema = z.object({
url: z.string().url("Please enter a valid URL"), url: z.string().url("Please enter a valid URL"),
slug: z.string().max(10, "Slug must be 10 characters or less"), slug: z.string().min(1).max(10, "Slug must be 10 characters or less"),
title: z.string().max(100, "Title must be 100 characters or less").transform(v => v.trim() === "" ? null : v).nullable(), title: z.string().max(100, "Title must be 100 characters or less").transform(v => v.trim() === "" ? null : v).nullable(),
maxVisits: z.number().int().positive().nullable(), maxVisits: z.number().int().positive().nullable(),
expDate: z.date().nullable(), expDate: z.date().nullable(),