// **** Components **** import { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle } from '@/components/ui/sheet' import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; import { CardHeaderBg } from '@/components/ui/card-header-bg'; import { AppIcon } from '@/components/icons'; import { Show, Index } from 'solid-js'; import { HelperText } from '@/components/ui/helper-text'; // **** Utils **** import { db } from '@/lib/sync/db'; import { generateId } from '@/lib/utils'; import { toast } from '@/components/ui/toast'; import { createGroupAction } from '@/domain/group/group.actions'; // **** Hooks **** import { useAppForm } from "@/components/form"; import { useQuery } from '@aboviq/powersync-solid'; // **** Types **** import type { Accessor, Setter } from "solid-js"; import { CreateGroupFormInput } from "@/domain/group/group.schema"; type CreateGroupFormProps = { dialogOpen: Accessor setDialogOpen: Setter orgId: string } export function CreateGroupForm(props: CreateGroupFormProps) { const defaultValues: typeof CreateGroupFormInput.infer = { name: '', description: '', permissions: [{ role: '', team: '' }], } const createGroupForm = useAppForm(() => ({ formId: 'create-group-form', defaultValues, validators: { onSubmitAsync: CreateGroupFormInput }, onSubmit: async ({ value, formApi }) => { try { await createGroupAction({ ...value, id: generateId(), organization_id: props.orgId, created_at: new Date().toISOString(), updated_at: new Date().toISOString() }) formApi.reset() props.setDialogOpen(false) toast({ variant: 'success', title: "Success", description: "Group created successfully" }) } catch (err) { console.error(err) toast({ variant: 'error', title: "Error", description: "Failed to create group" }) } } })) const [teams] = useQuery( db.selectFrom('team') .select(['id', 'name']) .where('organization_id', '=', props.orgId) ) const [roles] = useQuery( db.selectFrom('group_role') .select(['id', 'name']) .where('organization_id', '=', props.orgId) ) const teamOptions = () => teams()?.map(t => ({ label: t.name, value: t.id })) ?? [] const roleOptions = () => roles()?.map(r => ({ label: r.name, value: r.id })) ?? [] return ( Create group Create a new group and select the appropriate workspaces and roles {" "} that should apply across those workspaces
{ e.preventDefault() e.stopPropagation() createGroupForm.handleSubmit() }} class="grid grid-cols-1 gap-4" > } /> { return ( ) } } />
Select workspaces and the associated roles for the respective workspaces
{(field) => { return (
0}> {(_, i) => (
} />
} />
)}
) }}
) }