1+ import { format } from 'date-fns' ;
2+ import { FieldValues } from 'react-hook-form' ;
3+ import { ChangeEvent } from 'react' ;
4+
15import { createStatementProperty } from '@/src/components/form/jsf-utils/createFields' ;
26import { zendeskArticles } from '@/src/components/shared/zendesk-drawer/utils' ;
37import { ZendeskTriggerButton } from '@/src/components/shared/zendesk-drawer/ZendeskTriggerButton' ;
48import { ContractPreviewHeader } from '@/src/flows/ContractorOnboarding/components/ContractPreviewHeader' ;
59import { ContractPreviewStatement } from '@/src/flows/ContractorOnboarding/components/ContractPreviewStatement' ;
6- import { contractorStandardProductIdentifier } from '@/src/flows/ContractorOnboarding/constants' ;
7- import { ContractorOnboardingFlowProps } from '@/src/flows/ContractorOnboarding/types' ;
10+ import {
11+ contractorStandardProductIdentifier ,
12+ REMOTE_AI_SERVICES_AND_DELIVERABLES_COR_ERROR_MESSAGE ,
13+ REMOTE_AI_SERVICES_AND_DELIVERABLES_ERROR_MESSAGE ,
14+ } from '@/src/flows/ContractorOnboarding/constants' ;
15+ import {
16+ ContractorOnboardingFlowProps ,
17+ ContractorOnboardingContractDetailsFormPayload ,
18+ } from '@/src/flows/ContractorOnboarding/types' ;
819import { isNationalityCountryCode } from '@/src/flows/ContractorOnboarding/utils' ;
920import { JSFModify } from '@/src/flows/types' ;
1021import { FILE_TYPES , MAX_FILE_SIZE } from '@/src/lib/uploadConfig' ;
1122import { JSFCustomComponentProps } from '@/src/types/remoteFlows' ;
12- import { format } from 'date-fns' ;
13- import { FieldValues } from 'react-hook-form' ;
1423
1524const isStandardPricingPlan = ( pricingPlan : string | undefined ) => {
1625 return pricingPlan === contractorStandardProductIdentifier ;
@@ -36,6 +45,31 @@ const showBackDateWarning = (
3645 return undefined ;
3746} ;
3847
48+ /**
49+ * Handles changes to the services_and_deliverables field to clear AI warning state
50+ */
51+ function onServicesAndDeliverablesChange (
52+ _event : ChangeEvent < HTMLTextAreaElement > ,
53+ values : ContractorOnboardingContractDetailsFormPayload & {
54+ services_and_deliverables_ai_warning : string ;
55+ services_and_deliverables_error_skippable : boolean ;
56+ } ,
57+ setValues : (
58+ formValues : Partial <
59+ ContractorOnboardingContractDetailsFormPayload & {
60+ services_and_deliverables_ai_warning : string ;
61+ services_and_deliverables_error_skippable : boolean ;
62+ }
63+ > ,
64+ ) => void ,
65+ ) {
66+ setValues ( {
67+ ...values ,
68+ services_and_deliverables_ai_warning : '' ,
69+ services_and_deliverables_error_skippable : false ,
70+ } ) ;
71+ }
72+
3973/**
4074 * Merges internal jsfModify modifications with user-provided options for contract_details step
4175 * This abstracts the logic of applying internal field modifications (like dynamic descriptions)
@@ -46,6 +80,7 @@ export const buildContractDetailsJsfModify = (
4680 provisionalStartDateDescription : string | undefined ,
4781 selectedPricingPlan : string | undefined ,
4882 fieldValues : FieldValues ,
83+ isContractorOfRecord : boolean ,
4984) : JSFModify => {
5085 const isStandardPricingPlanSelected =
5186 isStandardPricingPlan ( selectedPricingPlan ) ;
@@ -55,8 +90,30 @@ export const buildContractDetailsJsfModify = (
5590 isStandardPricingPlanSelected ,
5691 provisionalStartDate ,
5792 ) ;
93+ const AiStatementWarning = createStatementProperty ( {
94+ severity : 'warning' ,
95+ title : 'Possible misclassification risk' ,
96+ description : isContractorOfRecord
97+ ? REMOTE_AI_SERVICES_AND_DELIVERABLES_COR_ERROR_MESSAGE
98+ : REMOTE_AI_SERVICES_AND_DELIVERABLES_ERROR_MESSAGE ,
99+ } ) ;
58100 return {
59101 ...userJsfModify ,
102+ create : {
103+ ...userJsfModify ?. create ,
104+ services_and_deliverables_ai_warning : {
105+ type : 'string' ,
106+ 'x-jsf-presentation' : {
107+ inputType : 'hidden' ,
108+ } ,
109+ } ,
110+ services_and_deliverables_error_skippable : {
111+ type : 'boolean' ,
112+ 'x-jsf-presentation' : {
113+ inputType : 'hidden' ,
114+ } ,
115+ } ,
116+ } ,
60117 fields : {
61118 ...userJsfModify ?. fields ,
62119 ...{
@@ -69,6 +126,16 @@ export const buildContractDetailsJsfModify = (
69126 ...statement ,
70127 } ,
71128 } ,
129+ services_and_deliverables : {
130+ onChange : onServicesAndDeliverablesChange ,
131+ 'x-jsf-presentation' : {
132+ calculateDynamicProperties : ( formValues : FieldValues ) => ( {
133+ statement : formValues . services_and_deliverables_ai_warning
134+ ? AiStatementWarning . statement
135+ : undefined ,
136+ } ) ,
137+ } ,
138+ } ,
72139 } ,
73140 } ,
74141 } ;
0 commit comments