diff --git a/apps/client/src/features/applications/components/ApplicationFlow.tsx b/apps/client/src/features/applications/components/ApplicationFlow.tsx new file mode 100644 index 0000000..115c767 --- /dev/null +++ b/apps/client/src/features/applications/components/ApplicationFlow.tsx @@ -0,0 +1,182 @@ +import { useQueryClient } from "@tanstack/react-query"; +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { Progress, useProgressContext } from "@/components/Progress"; +import { useCreateApplicationMutation, useCvQuery } from "@/generated/graphql"; +import { CVTemplateSelector } from "./CVTemplateSelector"; +import { VacancySelector } from "./VacancySelector"; + +export const ApplicationFlow = () => { + const navigate = useNavigate(); + const queryClient = useQueryClient(); + const [selectedVacancyId, setSelectedVacancyId] = useState( + null, + ); + const [selectedCVId, setSelectedCVId] = useState(null); + const [coverLetter, setCoverLetter] = useState(""); + + const createApplicationMutation = useCreateApplicationMutation(); + + const handleCancel = () => { + navigate("/dashboard"); + }; + + const handleSubmitApplication = async () => { + if (!(selectedVacancyId && selectedCVId)) { + return; + } + + try { + await createApplicationMutation.mutateAsync({ + input: { + vacancyId: selectedVacancyId, + cvId: selectedCVId, + coverLetter: coverLetter || null, + }, + }); + + // Invalidate and refetch application queries + await queryClient.invalidateQueries({ + queryKey: ["MyApplications"], + }); + + navigate("/applications", { + state: { message: "Application submitted successfully!" }, + }); + } catch (error) { + console.error("Failed to submit application:", error); + // Handle error (show toast, etc.) + } + }; + + return ( +
+
+ + + + + + + + + + + +
+
+ ); +}; + +interface ApplicationReviewProps { + vacancyId: string | null; + cvId: string | null; + coverLetter: string; + onCoverLetterChange: (value: string) => void; + onCancel: () => void; + onSubmit: () => void; + isSubmitting: boolean; +} + +const ApplicationReview = ({ + vacancyId, + cvId, + coverLetter, + onCoverLetterChange, + onCancel, + onSubmit, + isSubmitting, +}: ApplicationReviewProps) => { + const { back } = useProgressContext(); + const { data: cvData, isLoading: cvLoading } = useCvQuery( + { id: cvId ?? "" }, + { enabled: !!cvId }, + ); + + return ( +
+
+

Review Application

+

+ Review your application details before submitting +

+
+ +
+
+

Selected Vacancy

+

Vacancy ID: {vacancyId}

+
+ +
+

Selected CV

+ {cvLoading ? ( +

Loading...

+ ) : cvData?.cv ? ( +

{cvData.cv.title}

+ ) : ( +

CV ID: {cvId}

+ )} +
+ +
+ +