feat: 24 Char limit on channel names
This commit is contained in:
parent
25d32d07b2
commit
d61625771e
@ -6,10 +6,13 @@
|
|||||||
import type { NewChannelSchema } from '$lib/types/misc';
|
import type { NewChannelSchema } from '$lib/types/misc';
|
||||||
import type { Infer, SuperValidated } from 'sveltekit-superforms';
|
import type { Infer, SuperValidated } from 'sveltekit-superforms';
|
||||||
import { superForm } from 'sveltekit-superforms';
|
import { superForm } from 'sveltekit-superforms';
|
||||||
|
import { zodClient } from 'sveltekit-superforms/adapters';
|
||||||
|
import { newChannelSchema } from '$lib/types/misc';
|
||||||
|
|
||||||
let open: boolean = $state(false);
|
let open: boolean = $state(false);
|
||||||
let { data }: { data: SuperValidated<Infer<NewChannelSchema>> } = $props();
|
let { data }: { data: SuperValidated<Infer<NewChannelSchema>> } = $props();
|
||||||
const { form, errors, constraints, enhance } = superForm(data, {
|
const { form, errors, constraints, enhance } = superForm(data, {
|
||||||
|
validators: zodClient(newChannelSchema),
|
||||||
onResult: ({ result }) => {
|
onResult: ({ result }) => {
|
||||||
if (result.type === 'success') {
|
if (result.type === 'success') {
|
||||||
open = false;
|
open = false;
|
||||||
@ -36,7 +39,6 @@
|
|||||||
type="text"
|
type="text"
|
||||||
bind:value={$form.channelName}
|
bind:value={$form.channelName}
|
||||||
aria-invalid={$errors.channelName ? 'true' : undefined}
|
aria-invalid={$errors.channelName ? 'true' : undefined}
|
||||||
{...$constraints.channelName}
|
|
||||||
/>
|
/>
|
||||||
{#if $errors.channelName}<Label for="channelName" class="m-0 p-0 text-red-500">{$errors.channelName}</Label>{/if}
|
{#if $errors.channelName}<Label for="channelName" class="m-0 p-0 text-red-500">{$errors.channelName}</Label>{/if}
|
||||||
<Dialog.Footer>
|
<Dialog.Footer>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const newChannelSchema = z.object({
|
export const newChannelSchema = z.object({
|
||||||
channelName: z.string().min(1, 'Channel name is required'),
|
channelName: z.string().min(1, 'Channel name is required').max(24, 'Channel name cannot be longer than 24 characters.'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type NewChannelSchema = typeof newChannelSchema;
|
export type NewChannelSchema = typeof newChannelSchema;
|
||||||
|
Loading…
Reference in New Issue
Block a user