@@ -32,7 +32,7 @@ import { TicketsCardHooksSelectors, TicketsHooksSelectors } from '@/v5/services/
3232import { TicketsCardActionsDispatchers } from '@/v5/services/actionsDispatchers' ;
3333import { PaddedCrossIcon } from '@controls/chip/chip.styles' ;
3434import { ITicket } from '@/v5/store/tickets/tickets.types' ;
35- import { isEqual } from 'lodash' ;
35+ import { get , isEqual , set } from 'lodash' ;
3636import { useFormContext , useWatch } from 'react-hook-form' ;
3737import { DrawingViewerService } from '@components/viewer/drawingViewer/drawingViewer.service' ;
3838import { Pin } from '../../../pin' ;
@@ -43,20 +43,22 @@ export const CoordsProperty = ({ value, label, onChange, onBlur, required, error
4343 const prevValue = useRef ( undefined ) ;
4444 const { getValues } = useFormContext ( ) ;
4545 const ticket = getValues ( ) as ITicket ;
46- const selectedTemplateId = TicketsCardHooksSelectors . selectSelectedTemplateId ( ) ?? ticket ?. type ;
46+ const selectedTemplateId = ticket ?. type ?? TicketsCardHooksSelectors . selectSelectedTemplateId ( ) ;
4747 const template = TicketsHooksSelectors . selectTemplateById ( containerOrFederation , selectedTemplateId ) ;
4848 const selectedPin = TicketsCardHooksSelectors . selectSelectedTicketPinId ( ) ;
4949
50- const colourPropPath = getColorTriggerPropName ( name , template ) ;
51- useWatch ( { name :colourPropPath } ) ;
50+ const colorTriggerPropPath = getColorTriggerPropName ( name , template ) ;
51+ const colorTriggerPropValue = useWatch ( { name : colorTriggerPropPath } ) ?? get ( ticket , colorTriggerPropPath ) ;
5252
5353 const isNewTicket = ! ticket ?. _id ;
5454 const ticketId = ! isNewTicket ? ticket . _id : NEW_TICKET_ID ;
55+ const minimumPinTicket = set ( { _id : ticketId } , colorTriggerPropPath , colorTriggerPropValue ) as ITicket ;
56+
5557 const pinId = getPinId ( name , ticket ) ;
5658 const editMode = pinToDrop === pinId ;
5759 const isSelected = selectedPin === pinId ;
5860 const hasPin = ! ! value ;
59- const colorHex = getPinColorHexForProperty ( name , template , ticket ) ;
61+ const colorHex = getPinColorHexForProperty ( name , template , minimumPinTicket ) ;
6062 const pinIcon = getPinIconForProperty ( name , template ) ;
6163
6264 const cancelEdit = ( ) => {
@@ -105,7 +107,7 @@ export const CoordsProperty = ({ value, label, onChange, onBlur, required, error
105107 }
106108
107109 if ( hasPin ) {
108- ViewerService . showPin ( toPin ( name , template , ticket , false , value ) ) ;
110+ ViewerService . showPin ( toPin ( name , template , minimumPinTicket , false , value ) ) ;
109111 }
110112
111113 if ( isSelected ) ViewerService . setSelectionPin ( { id : pinId , isSelected } ) ;
0 commit comments