11"use client" ;
22
3- import { useCallback , useMemo } from "react" ;
3+ import Markdown from "react-markdown" ;
4+
5+ import { useCallback } from "react" ;
46
57import { useForm } from "react-hook-form" ;
68import { toast } from "react-toastify" ;
@@ -54,10 +56,45 @@ import {
5456 SelectItem ,
5557 SelectValue ,
5658} from "@/components/ui/select" ;
59+ import { Tooltip , TooltipArrow , TooltipContent , TooltipTrigger } from "@/components/ui/tooltip" ;
60+
61+ import { LuInfo } from "react-icons/lu" ;
62+
63+ import { TooltipPortal } from "@radix-ui/react-tooltip" ;
5764
5865import { updateOrCreateProject } from "@/services/projects" ;
5966import CSVImport from "@/components/new-dataset/step-description/csv-import" ;
6067import { useGetObjectives } from "@/types/generated/objective" ;
68+ import { useGetProjectFieldMetadata } from "@/types/generated/project-field-metadata" ;
69+
70+ const ProjectFieldLabel = ( {
71+ title,
72+ data,
73+ required = false ,
74+ } : {
75+ title : string ;
76+ data : string | undefined ;
77+ required ?: boolean ;
78+ } ) => (
79+ < FormLabel className = "flex items-center text-xs font-semibold" >
80+ < span >
81+ { title }
82+ { required && < sup className = "pl-0.5" > *</ sup > }
83+ </ span >
84+ < Tooltip >
85+ < TooltipTrigger >
86+ < LuInfo className = "h-4 w-4 pl-1 font-bold" />
87+ </ TooltipTrigger >
88+
89+ < TooltipPortal >
90+ < TooltipContent side = "right" align = "center" >
91+ < Markdown className = "prose text-xxs" > { data } </ Markdown >
92+ < TooltipArrow className = "fill-white" width = { 10 } height = { 5 } />
93+ </ TooltipContent >
94+ </ TooltipPortal >
95+ </ Tooltip >
96+ </ FormLabel >
97+ ) ;
6198
6299export default function ProjectForm ( ) {
63100 const { push, back } = useRouter ( ) ;
@@ -223,6 +260,8 @@ export default function ProjectForm() {
223260 } ,
224261 ) ;
225262
263+ const { data : dataInfo } = useGetProjectFieldMetadata ( ) ;
264+
226265 const { data : projectsSuggestedData } = useGetProjectEditSuggestionsId (
227266 + id ,
228267 {
@@ -608,9 +647,11 @@ export default function ProjectForm() {
608647 name = "description"
609648 render = { ( { field } ) => (
610649 < FormItem className = "space-y-1.5" >
611- < FormLabel className = "text-xs font-semibold" >
612- Description< sup className = "pl-0.5" > *</ sup >
613- </ FormLabel >
650+ < ProjectFieldLabel
651+ title = "Description"
652+ data = { dataInfo ?. data ?. attributes ?. highlight }
653+ required
654+ />
614655 < FormControl >
615656 < Input
616657 { ...field }
@@ -634,7 +675,7 @@ export default function ProjectForm() {
634675 name = "info"
635676 render = { ( { field } ) => (
636677 < FormItem className = "space-y-1.5" >
637- < FormLabel className = "text-xs font-semibold" > Info</ FormLabel >
678+ < ProjectFieldLabel title = " Info" data = { dataInfo ?. data ?. attributes ?. info } / >
638679 < FormControl >
639680 < Input
640681 { ...field }
@@ -660,9 +701,11 @@ export default function ProjectForm() {
660701 render = { ( { field } ) => {
661702 return (
662703 < FormItem className = "space-y-1.5" >
663- < FormLabel className = "text-xs font-semibold" >
664- Pillar< sup className = "pl-0.5" > *</ sup >
665- </ FormLabel >
704+ < ProjectFieldLabel
705+ title = "Pillar"
706+ data = { dataInfo ?. data ?. attributes ?. pillar }
707+ required
708+ />
666709 < Select value = { field . value ?. toString ( ) } onValueChange = { field . onChange } >
667710 < SelectTrigger
668711 className = { cn ( {
@@ -696,9 +739,11 @@ export default function ProjectForm() {
696739 name = "amount"
697740 render = { ( { field } ) => (
698741 < FormItem className = "space-y-1.5" >
699- < FormLabel className = "text-xs font-semibold" >
700- Amount (USD)< sup className = "pl-0.5" > *</ sup >
701- </ FormLabel >
742+ < ProjectFieldLabel
743+ title = "Amount (USD)"
744+ data = { dataInfo ?. data ?. attributes ?. amount }
745+ required
746+ />
702747 < FormControl >
703748 < Input
704749 { ...field }
@@ -723,9 +768,11 @@ export default function ProjectForm() {
723768 render = { ( { field } ) => {
724769 return (
725770 < FormItem className = "space-y-1.5" >
726- < FormLabel className = "text-xs font-semibold" >
727- Countries< sup className = "pl-0.5" > *</ sup >
728- </ FormLabel >
771+ < ProjectFieldLabel
772+ title = "Countries"
773+ data = { dataInfo ?. data ?. attributes ?. countries }
774+ required
775+ />
729776 < FormControl >
730777 < MultiCombobox
731778 values = { field . value }
@@ -749,9 +796,11 @@ export default function ProjectForm() {
749796 render = { ( { field } ) => {
750797 return (
751798 < FormItem className = "space-y-1.5" >
752- < FormLabel className = "text-xs font-semibold" >
753- SDG< sup className = "pl-0.5" > *</ sup >
754- </ FormLabel >
799+ < ProjectFieldLabel
800+ title = "SDG"
801+ data = { dataInfo ?. data ?. attributes ?. sdgs }
802+ required
803+ />
755804 < FormControl >
756805 < MultiCombobox
757806 values = { field . value }
@@ -774,9 +823,11 @@ export default function ProjectForm() {
774823 name = "status"
775824 render = { ( { field } ) => (
776825 < FormItem className = "space-y-1.5" >
777- < FormLabel className = "text-xs font-semibold" >
778- Status< sup className = "pl-0.5" > *</ sup >
779- </ FormLabel >
826+ < ProjectFieldLabel
827+ title = "Status"
828+ data = { dataInfo ?. data ?. attributes ?. status }
829+ required
830+ />
780831 < FormControl >
781832 < Select value = { field . value ?. toString ( ) } onValueChange = { field . onChange } >
782833 < SelectTrigger
@@ -812,9 +863,11 @@ export default function ProjectForm() {
812863 name = "funding"
813864 render = { ( { field } ) => (
814865 < FormItem className = "space-y-1.5" >
815- < FormLabel className = "text-xs font-semibold" >
816- Type of funding< sup className = "pl-0.5" > *</ sup >
817- </ FormLabel >
866+ < ProjectFieldLabel
867+ title = "Type of funding"
868+ data = { dataInfo ?. data ?. attributes ?. funding }
869+ required
870+ />
818871 < FormControl >
819872 < Select value = { field . value ?. toString ( ) } onValueChange = { field . onChange } >
820873 < SelectTrigger
@@ -850,9 +903,11 @@ export default function ProjectForm() {
850903 name = "organization_type"
851904 render = { ( { field } ) => (
852905 < FormItem className = "space-y-1.5" >
853- < FormLabel className = "text-xs font-semibold" >
854- Organization type< sup className = "pl-0.5" > *</ sup >
855- </ FormLabel >
906+ < ProjectFieldLabel
907+ title = "Organization type"
908+ data = { dataInfo ?. data ?. attributes ?. organization_type }
909+ required
910+ />
856911 < FormControl >
857912 < Select value = { field . value ?. toString ( ) } onValueChange = { field . onChange } >
858913 < SelectTrigger
@@ -887,9 +942,11 @@ export default function ProjectForm() {
887942 name = "source_country"
888943 render = { ( { field } ) => (
889944 < FormItem className = "space-y-1.5" >
890- < FormLabel className = "text-xs font-semibold" >
891- Source country< sup className = "pl-0.5" > *</ sup >
892- </ FormLabel >
945+ < ProjectFieldLabel
946+ title = "Source country"
947+ data = { dataInfo ?. data ?. attributes ?. source_country }
948+ required
949+ />
893950 < FormControl >
894951 < Select value = { field . value ?. toString ( ) } onValueChange = { field . onChange } >
895952 < SelectTrigger
@@ -925,9 +982,11 @@ export default function ProjectForm() {
925982 name = "objective"
926983 render = { ( { field } ) => (
927984 < FormItem className = "space-y-1.5" >
928- < FormLabel className = "text-xs font-semibold" >
929- Objective< sup className = "pl-0.5" > *</ sup >
930- </ FormLabel >
985+ < ProjectFieldLabel
986+ title = "Objective"
987+ data = { dataInfo ?. data ?. attributes ?. objective }
988+ required
989+ />
931990 < FormControl >
932991 < Select value = { field . value ?. toString ( ) } onValueChange = { field . onChange } >
933992 < SelectTrigger
0 commit comments