diff --git a/src/app/dashboard/decisions/register/page.tsx b/src/app/dashboard/decisions/register/page.tsx new file mode 100644 index 0000000..7eb13f5 --- /dev/null +++ b/src/app/dashboard/decisions/register/page.tsx @@ -0,0 +1,326 @@ +'use client'; + +import { useState } from 'react'; +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; +import { apiFetch, type Decision } from '../../../../lib/api'; +import { useSession } from '../../../../components/session-provider'; + +const createDecisionSchema = z.object({ + context: z.string().min(1, 'Contextul este obligatoriu').max(2000), + optionsText: z.string().optional(), + reviewDueAt: z.string().optional(), +}); +type CreateDecisionForm = z.infer; + +function parseOptions(text: string): string[] { + return text.split('\n').map((s) => s.trim()).filter(Boolean); +} + +function DecisionCard({ + decision, + tenantId, + onUpdated, +}: { + decision: Decision; + tenantId: string; + onUpdated: () => Promise; +}) { + const [isExpanded, setIsExpanded] = useState(false); + const [selectedOption, setSelectedOption] = useState(decision.selectedOption ?? ''); + const [outcomeReview, setOutcomeReview] = useState(decision.outcomeReview ?? ''); + + const options = (decision.options as string[]).filter(Boolean); + const isDecided = Boolean(decision.selectedOption); + const isOverdue = + decision.reviewDueAt ? new Date(decision.reviewDueAt) < new Date() : false; + + const updateMutation = useMutation({ + mutationFn: (dto: { selectedOption?: string; outcomeReview?: string }) => + apiFetch(`/v1/decisions/${decision.id}`, { + method: 'PATCH', + tenantId, + body: dto, + }), + onSuccess: async () => { + await onUpdated(); + }, + }); + + return ( +
  • + + + {isExpanded && ( +
    + {decision.selectedOption && ( +
    + Decizie luată: {decision.selectedOption} +
    + )} + + {options.length > 0 && ( +
    +

    Selectează opțiunea

    +
    + {options.map((opt, i) => ( + + ))} +
    +
    + )} + +
    + +