Skip to content

Commit

Permalink
Feat/389 (#390)
Browse files Browse the repository at this point in the history
* feat: Multi-Step Form

* feat: changes ui

* feat: Gemini Integaretion

* feat: Modal For Cover Letter
  • Loading branch information
Sid-80 authored Jul 19, 2024
1 parent 4fe74ef commit c28e1f3
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 7 deletions.
70 changes: 70 additions & 0 deletions components/CoverLetterDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { SetStateAction, useState } from "react";
import { Textarea } from "./ui/textarea";
import { Button } from "./ui/button";
import { useToast } from "./ui/use-toast";

type Props = {
setIsResponseGenerated: React.Dispatch<SetStateAction<boolean>>;
setResponse: React.Dispatch<SetStateAction<string>>;
isResponseGenerated: boolean;
response: string;
isError: boolean;
};

export default function CoverLetterDialog({
isResponseGenerated,
setIsResponseGenerated,
response,
setResponse,
isError,
}: Props) {
const { toast } = useToast();
const copyHandler = () => {
navigator.clipboard.writeText(response);
toast({
title: "Cover Letter",
description: "Text Copied!!",
});
};

return (
<Dialog open={isResponseGenerated} onOpenChange={setIsResponseGenerated}>
<DialogTrigger></DialogTrigger>
<DialogContent className="sm:w-[700px]">
{!isError && (
<>
<DialogHeader className="flex flex-row w-full items-center justify-between">
<DialogTitle>Cover Letter</DialogTitle>
</DialogHeader>

<Textarea
className="w-full sm:h-[550px] h-[400px]"
value={response}
onChange={(e) => setResponse(e.target.value)}
></Textarea>

<Button onClick={() => copyHandler()}>Copy!</Button>
</>
)}
{isError && (
<>
<DialogHeader className="flex flex-row w-full items-center justify-between">
<DialogTitle>Error</DialogTitle>
</DialogHeader>
<DialogDescription>
Error Occured!! Please try again later.
</DialogDescription>
</>
)}
</DialogContent>
</Dialog>
);
}
25 changes: 18 additions & 7 deletions components/CoverLetterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
} from "@/components/ui/form";
import { Textarea } from "./ui/textarea";
import { ArrowRightIcon } from "@radix-ui/react-icons";
import { SetStateAction } from "react";
import { SetStateAction, useState } from "react";
import { getCoverLetter } from "@/utils/Gemini";
import Loader from "./Loader";


const formSchema = z.object({
jobDescription: z
Expand Down Expand Up @@ -52,6 +54,8 @@ export default function CoverLetterForm({
setIsError,
setResponse,
}: Props) {
const [isLoading, setIsLoading] = useState(false);

const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
Expand Down Expand Up @@ -83,9 +87,8 @@ export default function CoverLetterForm({
}

const onSubmit = async (values: z.infer<typeof formSchema>) => {
// Do something with the form values.
// ✅ This will be type-safe and validated.
const { jobDescription, project, skills, experience } = values;
setIsLoading(true);

try {
const res = await getCoverLetter({
Expand All @@ -95,10 +98,14 @@ export default function CoverLetterForm({
experience,
});

console.log(res);
if (res) {
setIsResponseGenerated(true);
setResponse(res);
}
} catch (err) {
setIsError(true);
}
setIsLoading(false);
};

return (
Expand Down Expand Up @@ -223,7 +230,7 @@ export default function CoverLetterForm({
name="skills"
render={({ field }) => (
<FormItem>
<FormLabel>Projects</FormLabel>
<FormLabel>Skills</FormLabel>
<FormControl>
<Textarea
className="h-[100px]"
Expand Down Expand Up @@ -269,8 +276,12 @@ export default function CoverLetterForm({
</FormItem>
)}
/>
<Button className="flex gap-1 text-white" type="submit">
Submit
<Button
disabled={isLoading}
className="flex gap-1 text-white"
type="submit"
>
{isLoading ? <Loader /> : "Submit"}
</Button>
</>
)}
Expand Down
12 changes: 12 additions & 0 deletions components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";

export default function Loader() {
return (
<div className="flex gap-2 justify-center items-center">
<span className="sr-only">Loading...</span>
<div className="h-2 w-2 bg-black rounded-full animate-pulse [animation-delay:-0.3s]"></div>
<div className="h-2 w-2 bg-black rounded-full animate-pulse [animation-delay:-0.15s]"></div>
<div className="h-2 w-2 bg-black rounded-full animate-pulse"></div>
</div>
);
}
8 changes: 8 additions & 0 deletions components/cover-letter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRouter } from "next/navigation";
import React, { useState } from "react";
import { Button } from "./ui/button";
import CoverLetterForm from "./CoverLetterForm";
import CoverLetterDialog from "./CoverLetterDialog";

type Props = {
user: User | null;
Expand Down Expand Up @@ -76,6 +77,13 @@ export default function CoverLetter({ user }: Props) {
setIsSubmit={setIsSubmit}
/>
</div>
<CoverLetterDialog
setResponse={setResponse}
isResponseGenerated={isResponseGenerated}
setIsResponseGenerated={setIsResponseGenerated}
response={response}
isError={isError}
/>
</div>
</div>
);
Expand Down

0 comments on commit c28e1f3

Please sign in to comment.