/** * ProjectSelect — a gated project picker reused by the quote / contract / * hours / event editors to link a document to a Project Overview project. * * Renders nothing when the `projects` feature flag is off, so every call * site stays a one-liner that simply vanishes when the feature is disabled * (the maintainer's "book to project must not show unless projects is * enabled" requirement). Customers never see this — admin surfaces only. */ import React from 'react'; import { useQuery } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { useFeatureFlags } from '../../contexts/FeatureFlagsContext'; import { projectsService } from '../../services/projects.service'; interface ProjectSelectProps { value: number | null; onChange: (projectId: number | null) => void; /** Optional label above the select. When omitted the select renders bare. */ label?: string; /** Restrict the list to a single customer's projects when set. */ customerAccountId?: number | null; disabled?: boolean; className?: string; } export const ProjectSelect: React.FC = ({ value, onChange, label, customerAccountId, disabled, className, }) => { const { t } = useTranslation(); const { flags } = useFeatureFlags(); const { data: projects, isLoading } = useQuery({ queryKey: ['projects', 'select'], queryFn: () => projectsService.list(), enabled: !!flags.projects, staleTime: 60_000, }); // Hard gate: hidden entirely when the feature is off. if (!flags.projects) return null; const options = (projects || []).filter( (p) => customerAccountId == null || p.customerAccountId == null || p.customerAccountId === customerAccountId, ); return (
{label && ( )}
); };