diff --git a/app/opportunities/[opportunity_id]/edit/_components/general/generalEditForm.tsx b/app/opportunities/[opportunity_id]/edit/_components/general/generalEditForm.tsx index 7bd037b3..18ea0839 100644 --- a/app/opportunities/[opportunity_id]/edit/_components/general/generalEditForm.tsx +++ b/app/opportunities/[opportunity_id]/edit/_components/general/generalEditForm.tsx @@ -5,7 +5,6 @@ import { GeneralInformationSchema } from "@lib/schemas/opportunity"; import { Save } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@components/ui/button"; -import { useRouter } from "next/navigation"; import { type Session } from "next-auth"; import Breadcrumbs from "@components/ui/breadcrumbs"; import { Form } from "@components/ui/form"; @@ -16,13 +15,12 @@ import { GeneralInformation } from "../../../_components/general/general"; import { DeleteButton } from "../deleteButton"; interface Props { - session: Session; defaultValues: z.infer; update: ( input: z.infer, ) => Promise; } -const EditGeneralForm = ({ session, defaultValues, update }: Props) => { +const EditGeneralForm = ({ defaultValues, update }: Props) => { const form = useForm>({ resolver: zodResolver(GeneralInformationSchema), defaultValues, diff --git a/app/opportunities/[opportunity_id]/edit/_components/general/index.tsx b/app/opportunities/[opportunity_id]/edit/_components/general/index.tsx index c288ab47..60abcf47 100644 --- a/app/opportunities/[opportunity_id]/edit/_components/general/index.tsx +++ b/app/opportunities/[opportunity_id]/edit/_components/general/index.tsx @@ -61,11 +61,5 @@ export async function EditGeneral({ }); } - return ( - - ); + return ; } diff --git a/app/opportunities/[opportunity_id]/edit/_components/phases/editPhasesForm.tsx b/app/opportunities/[opportunity_id]/edit/_components/phases/editPhasesForm.tsx index a770a4cb..86160fd1 100644 --- a/app/opportunities/[opportunity_id]/edit/_components/phases/editPhasesForm.tsx +++ b/app/opportunities/[opportunity_id]/edit/_components/phases/editPhasesForm.tsx @@ -2,10 +2,10 @@ import Phase from "./phases/phase"; import { type z } from "zod"; -import { AddPhasePopover } from "./phases/addPhasePopover"; +import { PhasePopover } from "./phases/phasePopover"; import { type PhasesSchema } from "@lib/schemas/opportunity"; import { Button } from "@components/ui/button"; -import { Save } from "lucide-react"; +import { Plus, Save } from "lucide-react"; import { toast } from "sonner"; import { TallyForm } from "./tally/tallyForm"; import { createPhasesStore, PhasesContext } from "./usePhasesStore"; @@ -72,7 +72,7 @@ export function EditPhasesForm({ defaultValues, update }: Props) { /> ))} - appendPhase(data)} className="flex w-max opacity-0 transition-opacity group-hover/phases:opacity-100" /> diff --git a/app/opportunities/[opportunity_id]/edit/_components/phases/index.tsx b/app/opportunities/[opportunity_id]/edit/_components/phases/index.tsx index 7fc99621..e4a13388 100644 --- a/app/opportunities/[opportunity_id]/edit/_components/phases/index.tsx +++ b/app/opportunities/[opportunity_id]/edit/_components/phases/index.tsx @@ -32,6 +32,7 @@ export async function EditPhases({ opportunityId }: { opportunityId: string }) { const defaultPhases = opportunity.phases.map((phase) => ({ id: phase.id, name: phase.name, + isInterview: phase.isInterview, questionnaires: phase.questionnaires.map((questionnaire) => ({ id: questionnaire.id, name: questionnaire.name, diff --git a/app/opportunities/[opportunity_id]/edit/_components/phases/phases/addPhasePopover.tsx b/app/opportunities/[opportunity_id]/edit/_components/phases/phases/addPhasePopover.tsx deleted file mode 100644 index 4929485d..00000000 --- a/app/opportunities/[opportunity_id]/edit/_components/phases/phases/addPhasePopover.tsx +++ /dev/null @@ -1,94 +0,0 @@ -import { Button } from "@components/ui/button"; -import { Input } from "@components/ui/input"; -import { - Popover, - PopoverContent, - PopoverTrigger, -} from "@components/ui/popover"; -import { - type SubmitHandler, - type UseFieldArrayAppend, - useForm, -} from "react-hook-form"; -import { type PhasesSchema, PhaseSchema } from "@lib/schemas/opportunity"; -import { type z } from "zod"; -import { useState } from "react"; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@components/ui/form"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { Plus } from "lucide-react"; -import { type Phase as PhaseType } from "@lib/types/opportunity"; -import { v4 as uuidv4 } from "uuid"; -import { cn } from "@lib/utils"; - -interface Props { - onSave: (phase: PhaseType) => void; - className?: string; -} - -export const AddPhasePopover = ({ onSave, className }: Props) => { - const [popoverOpen, setPopoverOpen] = useState(false); - - const defaultValues = { - id: uuidv4(), - name: ``, - questionnaires: [], - }; - - const form = useForm>({ - resolver: zodResolver(PhaseSchema), - defaultValues, - }); - - const onSubmit: SubmitHandler> = (data) => { - onSave(data); - form.reset(defaultValues); - setPopoverOpen(false); - }; - - return ( - - - - - -
-

- Add Phase -

- - ( - - Name* - - - - - - )} - /> - - - -
-
- ); -}; diff --git a/app/opportunities/[opportunity_id]/edit/_components/phases/phases/phase.tsx b/app/opportunities/[opportunity_id]/edit/_components/phases/phases/phase.tsx index 7fa5db04..800c6c41 100644 --- a/app/opportunities/[opportunity_id]/edit/_components/phases/phases/phase.tsx +++ b/app/opportunities/[opportunity_id]/edit/_components/phases/phases/phase.tsx @@ -1,6 +1,13 @@ import { Button } from "@components/ui/button"; import { Separator } from "@components/ui/separator"; -import { Ellipsis, FolderPen, Move, Plus, Trash } from "lucide-react"; +import { + Ellipsis, + FolderPen, + Handshake, + Move, + Plus, + Trash, +} from "lucide-react"; import { QuestionnaireDialog } from "../questionnaire/questionnaireDialog"; import { Card } from "@components/ui/card"; import { @@ -17,6 +24,7 @@ import { } from "@components/ui/tooltip"; import { usePhasesContext } from "../usePhasesStore"; import { cn } from "@lib/utils"; +import { PhasePopover } from "./phasePopover"; interface Props { index: number; @@ -28,6 +36,7 @@ export default function Phase({ index: phaseIndex, className }: Props) { if (!phase) throw new Error(`Phase does not exist at index ${phaseIndex}`); const onRemove = usePhasesContext((s) => s.removePhase); + const onSave = usePhasesContext((s) => s.updatePhase)(phaseIndex); const appendQuestionnaire = usePhasesContext((s) => s.appendQuestionnaire)( phaseIndex, ); @@ -41,10 +50,11 @@ export default function Phase({ index: phaseIndex, className }: Props) { return (
-

+

+ {phase.isInterview && } {phase.name}

-
+
+ + + )} + + +
+ +

+ {initialDefaultValues ? "Edit" : "Add"} Phase +

+ + ( + + Name* + + + + + + )} + /> + + ( + + + + +
+ Is Interview + + Applications for interviews can be manually picked + +
+
+ )} + /> + + + + +
+ + ); +}; diff --git a/app/opportunities/[opportunity_id]/edit/_components/phases/questionnaire/questionnaireDialog.tsx b/app/opportunities/[opportunity_id]/edit/_components/phases/questionnaire/questionnaireDialog.tsx index 8b3257a6..19eda981 100644 --- a/app/opportunities/[opportunity_id]/edit/_components/phases/questionnaire/questionnaireDialog.tsx +++ b/app/opportunities/[opportunity_id]/edit/_components/phases/questionnaire/questionnaireDialog.tsx @@ -35,6 +35,7 @@ import { Card } from "@components/ui/card"; import { QuestionForm, type QuestionFormProps } from "./question"; import type { Question } from "@lib/types/question"; import { UsersStack } from "../../usersStack"; +import { useSession } from "next-auth/react"; const QuestionEdit = ({ question, diff --git a/app/opportunities/[opportunity_id]/edit/_components/phases/usePhasesStore.ts b/app/opportunities/[opportunity_id]/edit/_components/phases/usePhasesStore.ts index 17de4d55..561dfc57 100644 --- a/app/opportunities/[opportunity_id]/edit/_components/phases/usePhasesStore.ts +++ b/app/opportunities/[opportunity_id]/edit/_components/phases/usePhasesStore.ts @@ -1,6 +1,6 @@ import { type Phase, type Questionnaire } from "@lib/types/opportunity"; import { createStore, useStore } from "zustand"; -import { createContext, useContext, useRef } from "react"; +import { createContext, useContext } from "react"; import { immer } from "zustand/middleware/immer"; interface Props { @@ -9,6 +9,7 @@ interface Props { interface PhasesState extends Props { appendPhase: (data: Phase) => void; + updatePhase: (index: number) => (data: Phase) => void; removePhase: (index: number) => void; appendQuestionnaire: ( @@ -37,6 +38,10 @@ export const createPhasesStore = (initProps?: Partial) => { set((state) => { state.phases.push(data); }), + updatePhase: (index) => (data) => + set((state) => { + state.phases[index] = data; + }), removePhase: (index) => set((state) => { state.phases.splice(index, 1); diff --git a/app/opportunities/[opportunity_id]/edit/_components/usersStack.tsx b/app/opportunities/[opportunity_id]/edit/_components/usersStack.tsx index fcbc73e9..ac7a8fa7 100644 --- a/app/opportunities/[opportunity_id]/edit/_components/usersStack.tsx +++ b/app/opportunities/[opportunity_id]/edit/_components/usersStack.tsx @@ -9,6 +9,7 @@ import { } from "@components/ui/tooltip"; import { AddUserPopup } from "@components/user/addUserPopup"; import { type Person } from "@lib/types/person"; +import { cn } from "@lib/utils"; import { Minus, Plus, UserMinus } from "lucide-react"; interface Props { @@ -46,7 +47,7 @@ export const UsersStack = ({ users, append, remove, key }: Props) => { ))} - +