Files
Reactive-Resume/apps/client/src/pages/builder/sidebars/left/dialogs/projects.tsx
Amruth Pillai e87b05a93a release: v4.1.0
2024-05-05 14:55:06 +02:00

172 lines
5.1 KiB
TypeScript

import { zodResolver } from "@hookform/resolvers/zod";
import { t } from "@lingui/macro";
import { X } from "@phosphor-icons/react";
import { defaultProject, projectSchema } from "@reactive-resume/schema";
import {
Badge,
BadgeInput,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
Input,
RichInput,
} from "@reactive-resume/ui";
import { AnimatePresence, motion } from "framer-motion";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { AiActions } from "@/client/components/ai-actions";
import { SectionDialog } from "../sections/shared/section-dialog";
import { URLInput } from "../sections/shared/url-input";
const formSchema = projectSchema;
type FormValues = z.infer<typeof formSchema>;
export const ProjectsDialog = () => {
const form = useForm<FormValues>({
defaultValues: defaultProject,
resolver: zodResolver(formSchema),
});
const [pendingKeyword, setPendingKeyword] = useState("");
return (
<SectionDialog<FormValues>
id="projects"
form={form}
defaultValues={defaultProject}
pendingKeyword={pendingKeyword}
>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
<FormField
name="name"
control={form.control}
render={({ field }) => (
<FormItem>
<FormLabel>{t`Name`}</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="description"
control={form.control}
render={({ field }) => (
<FormItem>
<FormLabel>{t`Description`}</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="date"
control={form.control}
render={({ field }) => (
<FormItem>
<FormLabel>{t`Date or Date Range`}</FormLabel>
<FormControl>
<Input {...field} placeholder={t`March 2023 - Present`} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="url"
control={form.control}
render={({ field }) => (
<FormItem>
<FormLabel>{t`Website`}</FormLabel>
<FormControl>
<URLInput {...field} placeholder="https://rxresu.me" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="summary"
control={form.control}
render={({ field }) => (
<FormItem className="sm:col-span-2">
<FormLabel>{t`Summary`}</FormLabel>
<FormControl>
<RichInput
{...field}
content={field.value}
footer={(editor) => (
<AiActions value={editor.getText()} onChange={editor.commands.setContent} />
)}
onChange={(value) => {
field.onChange(value);
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="keywords"
control={form.control}
render={({ field }) => (
<div className="space-y-3 sm:col-span-2">
<FormItem>
<FormLabel>{t`Keywords`}</FormLabel>
<FormControl>
<BadgeInput {...field} setPendingKeyword={setPendingKeyword} />
</FormControl>
<FormDescription>
{t`You can add multiple keywords by separating them with a comma or pressing enter.`}
</FormDescription>
<FormMessage />
</FormItem>
<div className="flex flex-wrap items-center gap-x-2 gap-y-3">
<AnimatePresence>
{field.value.map((item, index) => (
<motion.div
key={item}
layout
initial={{ opacity: 0, y: -50 }}
animate={{ opacity: 1, y: 0, transition: { delay: index * 0.1 } }}
exit={{ opacity: 0, x: -50 }}
>
<Badge
className="cursor-pointer"
onClick={() => {
field.onChange(field.value.filter((v) => item !== v));
}}
>
<span className="mr-1">{item}</span>
<X size={12} weight="bold" />
</Badge>
</motion.div>
))}
</AnimatePresence>
</div>
</div>
)}
/>
</div>
</SectionDialog>
);
};