@@ -16,6 +16,7 @@ import { CippFormCondition } from '../CippComponents/CippFormCondition'
1616import { CippFormUserSelector } from '../CippComponents/CippFormUserSelector'
1717import { useWatch } from 'react-hook-form'
1818import { ApiGetCall } from '../../api/ApiCall'
19+ import { getCippValidator } from '../../utils/get-cipp-validator'
1920
2021export const CippWizardVacationActions = ( props ) => {
2122 const { postUrl, formControl, onPreviousStep, onNextStep, currentStep, lastStep } = props
@@ -25,12 +26,14 @@ export const CippWizardVacationActions = (props) => {
2526
2627 const enableCA = useWatch ( { control : formControl . control , name : 'enableCAExclusion' } )
2728 const enableMailbox = useWatch ( { control : formControl . control , name : 'enableMailboxPermissions' } )
29+ const enableForwarding = useWatch ( { control : formControl . control , name : 'enableForwarding' } )
2830 const enableOOO = useWatch ( { control : formControl . control , name : 'enableOOO' } )
29- const atLeastOneEnabled = enableCA || enableMailbox || enableOOO
31+ const atLeastOneEnabled = enableCA || enableMailbox || enableForwarding || enableOOO
3032
3133 const users = useWatch ( { control : formControl . control , name : 'Users' } )
3234 const firstUser = Array . isArray ( users ) && users . length > 0 ? users [ 0 ] : null
3335 const firstUserUpn = firstUser ?. addedFields ?. userPrincipalName || firstUser ?. value || null
36+ const forwardOption = useWatch ( { control : formControl . control , name : 'forwardOption' } )
3437
3538 const oooData = ApiGetCall ( {
3639 url : '/api/ListOoO' ,
@@ -41,6 +44,41 @@ export const CippWizardVacationActions = (props) => {
4144
4245 const isFetchingOOO = oooData . isFetching
4346
47+ const forwardingUsers = ApiGetCall ( {
48+ url : '/api/ListGraphRequest' ,
49+ data : {
50+ Endpoint : 'users' ,
51+ tenantFilter : tenantDomain ,
52+ $select : 'id,displayName,userPrincipalName,mail' ,
53+ $top : 999 ,
54+ } ,
55+ queryKey : `VacationForwardingUsers-${ tenantDomain } ` ,
56+ waiting : ! ! ( enableForwarding && tenantDomain ) ,
57+ } )
58+
59+ const forwardingContacts = ApiGetCall ( {
60+ url : '/api/ListGraphRequest' ,
61+ data : {
62+ Endpoint : 'contacts' ,
63+ tenantFilter : tenantDomain ,
64+ $select : 'displayName,mail,mailNickname' ,
65+ $top : 999 ,
66+ } ,
67+ queryKey : `VacationForwardingContacts-${ tenantDomain } ` ,
68+ waiting : ! ! ( enableForwarding && tenantDomain ) ,
69+ } )
70+
71+ const internalAddressOptions = [
72+ ...( ( forwardingUsers . data ?. Results || [ ] ) . map ( ( user ) => ( {
73+ value : user . userPrincipalName ,
74+ label : `${ user . displayName } (${ user . userPrincipalName } ) - User` ,
75+ } ) ) || [ ] ) ,
76+ ...( ( forwardingContacts . data ?. Results || [ ] ) . map ( ( contact ) => ( {
77+ value : contact . mail || contact . emailAddress ,
78+ label : `${ contact . displayName } (${ contact . mail || contact . emailAddress } ) - Contact` ,
79+ } ) ) || [ ] ) ,
80+ ]
81+
4482 useEffect ( ( ) => {
4583 if ( oooData . isSuccess && oooData . data ) {
4684 const currentInternal = formControl . getValues ( 'oooInternalMessage' )
@@ -71,7 +109,13 @@ export const CippWizardVacationActions = (props) => {
71109 formControl . setValue ( 'oooDeclineMeetingMessage' , oooData . data . DeclineMeetingMessage )
72110 }
73111 }
74- } , [ oooData . isSuccess , oooData . data ] )
112+ } , [ oooData . isSuccess , oooData . data , formControl ] )
113+
114+ useEffect ( ( ) => {
115+ if ( enableForwarding && ! forwardOption ) {
116+ formControl . setValue ( 'forwardOption' , 'internalAddress' )
117+ }
118+ } , [ enableForwarding , forwardOption , formControl ] )
75119
76120 return (
77121 < Stack spacing = { 4 } >
@@ -318,6 +362,120 @@ export const CippWizardVacationActions = (props) => {
318362 </ CardContent >
319363 </ Card >
320364
365+ { /* Mail Forwarding Section */ }
366+ < Card variant = "outlined" >
367+ < CardHeader
368+ title = "Mail Forwarding"
369+ subheader = "Forward email to another recipient during the vacation period"
370+ />
371+ < Divider />
372+ < CardContent >
373+ < Stack spacing = { 2 } >
374+ < CippFormComponent
375+ type = "switch"
376+ name = "enableForwarding"
377+ label = "Enable Mail Forwarding"
378+ formControl = { formControl }
379+ />
380+
381+ < CippFormCondition
382+ formControl = { formControl }
383+ field = "enableForwarding"
384+ compareType = "is"
385+ compareValue = { true }
386+ clearOnHide = { false }
387+ >
388+ < Grid container spacing = { 2 } >
389+ < Grid size = { { xs : 12 } } >
390+ < Alert severity = "info" sx = { { mb : 1 } } >
391+ Vacation mode will enable forwarding at the start date and disable forwarding
392+ again at the end date. Existing forwarding settings are not restored after the
393+ vacation ends.
394+ </ Alert >
395+ </ Grid >
396+ < Grid size = { { xs : 12 } } >
397+ < CippFormComponent
398+ type = "radio"
399+ name = "forwardOption"
400+ formControl = { formControl }
401+ options = { [
402+ { label : 'Forward to Internal Address' , value : 'internalAddress' } ,
403+ {
404+ label : 'Forward to External Address (Tenant must allow this)' ,
405+ value : 'ExternalAddress' ,
406+ } ,
407+ ] }
408+ />
409+ </ Grid >
410+
411+ < CippFormCondition
412+ formControl = { formControl }
413+ field = "forwardOption"
414+ compareType = "is"
415+ compareValue = "internalAddress"
416+ >
417+ < Grid size = { { xs : 12 } } >
418+ < CippFormComponent
419+ type = "autoComplete"
420+ label = {
421+ tenantDomain
422+ ? `Forward to user or contact in ${ tenantDomain } `
423+ : 'Select a tenant first'
424+ }
425+ name = "forwardInternal"
426+ multiple = { false }
427+ options = { internalAddressOptions }
428+ formControl = { formControl }
429+ creatable = { false }
430+ disabled = { ! tenantDomain }
431+ validators = { {
432+ validate : ( option ) => {
433+ if ( ! option ?. value && ! option ) {
434+ return 'Forwarding target is required'
435+ }
436+ return true
437+ } ,
438+ } }
439+ required = { true }
440+ />
441+ </ Grid >
442+ </ CippFormCondition >
443+
444+ < CippFormCondition
445+ formControl = { formControl }
446+ field = "forwardOption"
447+ compareType = "is"
448+ compareValue = "ExternalAddress"
449+ >
450+ < Grid size = { { xs : 12 } } >
451+ < CippFormComponent
452+ type = "textField"
453+ label = "External Email Address"
454+ name = "forwardExternal"
455+ formControl = { formControl }
456+ validators = { {
457+ required : 'Email is required' ,
458+ validate : ( value ) => getCippValidator ( value , 'email' ) ,
459+ } }
460+ required = { true }
461+ />
462+ </ Grid >
463+ </ CippFormCondition >
464+
465+ < Grid size = { { xs : 12 } } >
466+ < CippFormComponent
467+ type = "switch"
468+ label = "Keep a Copy of the Forwarded Mail in the Source Mailbox"
469+ name = "forwardKeepCopy"
470+ formControl = { formControl }
471+ />
472+ </ Grid >
473+ </ Grid >
474+ </ CippFormCondition >
475+ </ Stack >
476+ </ CardContent >
477+ </ Card >
478+
321479 { /* Out of Office Section */ }
322480 < Card variant = "outlined" >
323481 < CardHeader
0 commit comments