Skip to content

Commit

Permalink
feat(dashboard): Create workflow sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
desiprisg committed Oct 16, 2024
1 parent 67a55e1 commit 38c33ca
Show file tree
Hide file tree
Showing 15 changed files with 1,295 additions and 746 deletions.
3 changes: 2 additions & 1 deletion apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@clerk/clerk-react": "^5.2.5",
"@hookform/resolvers": "^2.9.11",
"@hookform/resolvers": "^3.9.0",
"@novu/react": "^2.3.0",
"@novu/shared": "workspace:*",
"@radix-ui/react-dialog": "^1.1.2",
Expand All @@ -32,6 +32,7 @@
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-scroll-area": "^1.2.0",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.3",
Expand Down
146 changes: 146 additions & 0 deletions apps/dashboard/src/components/create-workflow-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { Button } from '@/components/primitives/button';
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/primitives/form';
import { Input, InputField } from '@/components/primitives/input';
import { Separator } from '@/components/primitives/separator';
import {
Sheet,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetMain,
SheetTitle,
SheetTrigger,
} from '@/components/primitives/sheet';
import { TagInput } from '@/components/primitives/tag-input';
import { Textarea } from '@/components/primitives/textarea';
import { zodResolver } from '@hookform/resolvers/zod';
import { ComponentProps } from 'react';
import { useForm } from 'react-hook-form';
import { RiExternalLinkLine } from 'react-icons/ri';

import { Link } from 'react-router-dom';
import { z } from 'zod';

const formSchema = z.object({
name: z.string(),
identifier: z.string().regex(/^[a-z0-9-]+$/),
tags: z.array(z.string()).max(8),
description: z.string().max(200).optional(),
});

type CreateWorkflowButtonProps = ComponentProps<typeof SheetTrigger>;
export const CreateWorkflowButton = (props: CreateWorkflowButtonProps) => {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: { description: '', identifier: '', name: '', tags: [] },
});

return (
<Sheet>
<SheetTrigger {...props} />
<SheetContent>
<SheetHeader>
<SheetTitle>Create workflow</SheetTitle>
<div>
<SheetDescription>
Workflows manage event-driven notifications across multiple channels in a version-controlled flow, with
the ability to manage preference for each subscriber.
</SheetDescription>
<Link
target="_blank"
to="https://docs.novu.co/api-reference/workflows/create-workflow"
className="text-foreground-400 flex items-center text-sm underline"
>
Learn more <RiExternalLinkLine className="inline size-4" />
</Link>
</div>
</SheetHeader>
<Separator />
<SheetMain>
<Form {...form}>
<form
id="create-workflow"
onSubmit={form.handleSubmit((values) => {
console.log(values);
})}
className="flex flex-col gap-6"
>
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<InputField>
<Input placeholder="Untitled" {...field} />
</InputField>
</FormControl>
<FormMessage />
</FormItem>
)}
/>

<FormField
control={form.control}
name="identifier"
render={({ field }) => (
<FormItem>
<FormLabel>Identifier</FormLabel>
<FormControl>
<InputField>
<Input placeholder="untitled" {...field} />
</InputField>
</FormControl>
<FormMessage>Must be unique and all lowercase</FormMessage>
</FormItem>
)}
/>

<Separator className="bg-neutral-alpha-100" />

<FormField
control={form.control}
name="tags"
render={({ field }) => (
<FormItem>
<div className="flex items-center gap-1">
<FormLabel>Add tags</FormLabel>
<FormMessage>(max. 8)</FormMessage>
</div>
<FormControl>
<TagInput {...field} />
</FormControl>
</FormItem>
)}
/>

<FormField
control={form.control}
name="description"
render={({ field }) => (
<FormItem>
<div className="flex items-center gap-1">
<FormLabel optional>Description</FormLabel>
</div>
<FormControl>
<Textarea placeholder="Description of what this workflow does" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</form>
</Form>
</SheetMain>
<Separator />
<SheetFooter>
<Button variant="default" type="submit" form="create-workflow">
Create workflow
</Button>
</SheetFooter>
</SheetContent>
</Sheet>
);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useLayoutEffect, useState } from 'react';
import { RiLinkM, RiPencilFill } from 'react-icons/ri';
import { useForm } from 'react-hook-form';
// eslint-disable-next-line
// @ts-ignore
import { zodResolver } from '@hookform/resolvers/zod';
import * as z from 'zod';

Expand Down Expand Up @@ -86,7 +84,7 @@ export const EditBridgeUrlButton = () => {
<FormItem>
<FormLabel>Bridge Endpoint URL</FormLabel>
<FormControl>
<InputField variant="xs" state={errors.bridgeUrl?.message ? 'error' : 'default'}>
<InputField state={errors.bridgeUrl?.message ? 'error' : 'default'}>
<RiLinkM className="size-5 min-w-5" />
<Input id="bridgeUrl" {...field} />
</InputField>
Expand Down
17 changes: 11 additions & 6 deletions apps/dashboard/src/components/primitives/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Controller, ControllerProps, FieldPath, FieldValues, FormProvider } fro
import { cn } from '@/utils/ui';
import { Label } from '@/components/primitives/label';
import { cva } from 'class-variance-authority';
import { RiInformationFill } from 'react-icons/ri';
import { FormFieldContext, FormItemContext, useFormField } from './form-context';
import { RiErrorWarningFill, RiInformationFill } from 'react-icons/ri';

const Form = FormProvider;

Expand Down Expand Up @@ -39,11 +39,16 @@ FormItem.displayName = 'FormItem';

const FormLabel = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
>(({ className, ...props }, ref) => {
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & { optional?: boolean }
>(({ className, optional, children, ...props }, ref) => {
const { formItemId } = useFormField();

return <Label ref={ref} className={className} htmlFor={formItemId} {...props} />;
return (
<Label ref={ref} className={cn('text-foreground-950', className)} htmlFor={formItemId} {...props}>
{children}
{optional && <span className="text-foreground-400 ml-0.5">(optional)</span>}
</Label>
);
});
FormLabel.displayName = 'FormLabel';

Expand Down Expand Up @@ -78,7 +83,7 @@ FormDescription.displayName = 'FormDescription';
const formMessageVariants = cva('flex items-center gap-1', {
variants: {
variant: {
default: '[&>svg]:text-neutral-400 [&>span]:text-foreground-600',
default: '[&>svg]:text-foreground-300 text-foreground-400',
error: '[&>svg]:text-destructive [&>span]:text-destructive',
},
},
Expand All @@ -100,7 +105,7 @@ const FormMessage = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<
className={formMessageVariants({ variant: error ? 'error' : 'default', className })}
{...props}
>
<RiInformationFill className="size-4" />
{error ? <RiErrorWarningFill className="size-4" /> : <RiInformationFill className="size-4" />}
<span className="mt-[1px] text-xs leading-3">{body}</span>
</p>
);
Expand Down
19 changes: 11 additions & 8 deletions apps/dashboard/src/components/primitives/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ import { cn } from '@/utils/ui';
import { cva, VariantProps } from 'class-variance-authority';

const inputFieldVariants = cva(
'text-foreground-950 flex w-full flex-nowrap items-center gap-1.5 rounded-md border bg-transparent shadow-sm transition-colors focus-within:outline-none focus-visible:outline-none hover:bg-neutral-50 has-[input:disabled]:cursor-not-allowed has-[input:disabled]:opacity-50 has-[input[value=""]]:text-foreground-400 has-[input:disabled]:bg-neutral-100 has-[input:disabled]:text-foreground-300',
'text-foreground-950 flex w-full flex-nowrap items-center gap-1.5 rounded-md border bg-transparent shadow-sm transition-colors focus-within:outline-none focus-visible:outline-none hover:bg-neutral-50 has-[input:disabled]:cursor-not-allowed has-[input:disabled]:opacity-50 has-[input[value=""]]:text-foreground-400 has-[input:disabled]:bg-neutral-alpha-100 has-[input:disabled]:text-foreground-300',
{
variants: {
variant: {
default: 'h-10 px-3 [&>input]:py-2.5',
sm: 'h-9 px-2.5 [&>input]:py-2',
xs: 'h-8 px-2 [&>input]:py-1.5',
size: {
default: 'h-8 px-2 [&>input]:py-1.5',
},
state: {
default: 'border-neutral-200 focus-within:border-neutral-950 focus-visible:border-neutral-950',
default:
'border-neutral-alpha-200 focus-within:border-neutral-alpha-950 focus-visible:border-neutral-alpha-950',
error: 'border-destructive',
},
},
defaultVariants: {
size: 'default',
state: 'default',
},
}
);

export type InputFieldProps = { children: React.ReactNode; className?: string } & VariantProps<
typeof inputFieldVariants
>;

const InputField = ({ children, className, variant, state }: InputFieldProps) => {
return <div className={inputFieldVariants({ variant, state, className })}>{children}</div>;
const InputField = ({ children, className, size, state }: InputFieldProps) => {
return <div className={inputFieldVariants({ size, state, className })}>{children}</div>;
};

InputField.displayName = 'InputField';
Expand Down
24 changes: 24 additions & 0 deletions apps/dashboard/src/components/primitives/separator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import * as SeparatorPrimitive from '@radix-ui/react-separator';

import { cn } from '@/utils/ui';

const Separator = React.forwardRef<
React.ElementRef<typeof SeparatorPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
>(({ className, orientation = 'horizontal', decorative = true, ...props }, ref) => (
<SeparatorPrimitive.Root
ref={ref}
decorative={decorative}
orientation={orientation}
className={cn(
'bg-neutral-alpha-200 shrink-0',
orientation === 'horizontal' ? 'h-[1px] w-full' : 'h-full w-[1px]',
className
)}
{...props}
/>
));
Separator.displayName = SeparatorPrimitive.Root.displayName;

export { Separator };
Loading

0 comments on commit 38c33ca

Please sign in to comment.