import { ButtonContainer } from '@/components/button-container'; import { InputWithLabel, WithLabel } from '@/components/forms/input-with-label'; import TagInput from '@/components/forms/tag-input'; import { Button } from '@/components/ui/button'; import { CheckboxInput } from '@/components/ui/checkbox'; import { api, handleError } from '@/trpc/client'; import { zodResolver } from '@hookform/resolvers/zod'; import { useRouter } from 'next/navigation'; import { Controller, useForm } from 'react-hook-form'; import { toast } from 'sonner'; import { z } from 'zod'; import type { IServiceClient } from '@openpanel/db'; import { popModal } from '.'; import { ModalContent, ModalHeader } from './Modal/Container'; type EditClientProps = IServiceClient; const validator = z.object({ id: z.string().min(1), name: z.string().min(1), cors: z.string().nullable(), crossDomain: z.boolean().optional(), }); type IForm = z.infer; export default function EditClient({ id, name, cors, crossDomain, }: EditClientProps) { const router = useRouter(); const { register, handleSubmit, reset, formState, control, setError } = useForm({ resolver: zodResolver(validator), defaultValues: { id, name, cors, crossDomain, }, }); const mutation = api.client.update.useMutation({ onError: handleError, onSuccess() { reset(); toast('Success', { description: 'Client updated.', }); popModal(); router.refresh(); }, }); return (
{ if (!values.cors) { return setError('cors', { type: 'required', message: 'Please add a domain', }); } mutation.mutate(values); })} >
( (tag === '*' ? 'Allow all domains' : tag)} onChange={(newValue) => { field.onChange( newValue .map((item) => { const trimmed = item.trim(); if ( trimmed.startsWith('http://') || trimmed.startsWith('https://') || trimmed === '*' ) { return trimmed; } return `https://${trimmed}`; }) .join(','), ); }} /> )} /> { return (
Enable cross domain support
This will let you track users across multiple domains
); }} />
); }