1- import React , { useState } from "react" ;
1+ import React , { useState , useEffect } from "react" ;
22import { Divider , Button } from "@mui/material" ;
33import { Grid } from "@mui/system" ;
4- import { useForm } from "react-hook-form" ;
4+ import { useForm , useWatch , useFormState } from "react-hook-form" ;
55import { AccountCircle } from "@mui/icons-material" ;
66import { CippOffCanvas } from "./CippOffCanvas" ;
77import CippFormComponent from "./CippFormComponent" ;
@@ -23,9 +23,9 @@ export const CippAutopilotProfileDrawer = ({
2323 Description : "" ,
2424 DeviceNameTemplate : "" ,
2525 languages : null ,
26- CollectHash : true ,
26+ CollectHash : false ,
2727 Assignto : true ,
28- DeploymentMode : true ,
28+ DeploymentMode : false ,
2929 HideTerms : true ,
3030 HidePrivacy : true ,
3131 HideChangeAccount : true ,
@@ -37,15 +37,36 @@ export const CippAutopilotProfileDrawer = ({
3737
3838 const createProfile = ApiPostCall ( {
3939 urlFromData : true ,
40- relatedQueryKeys : [ "Autopilot Profiles" ] ,
40+ relatedQueryKeys : [ "Autopilot Profiles* " ] ,
4141 } ) ;
4242
43+ // Watch the deployment mode to conditionally disable white glove
44+ const deploymentMode = useWatch ( {
45+ control : formControl . control ,
46+ name : "DeploymentMode" ,
47+ } ) ;
48+
49+ // Watch form state for validation
50+ const { isValid, isDirty } = useFormState ( {
51+ control : formControl . control ,
52+ } ) ;
53+
54+ // Automatically disable white glove when self-deploying mode (shared) is enabled
55+ useEffect ( ( ) => {
56+ if ( deploymentMode === true ) {
57+ // Self-deploying mode is enabled (shared mode), disable white glove
58+ formControl . setValue ( "allowWhiteglove" , false ) ;
59+ }
60+ } , [ deploymentMode , formControl ] ) ;
61+
4362 const handleSubmit = ( ) => {
4463 const formData = formControl . getValues ( ) ;
64+ // Always set HideChangeAccount to true regardless of form state
65+ formData . HideChangeAccount = true ;
4566 createProfile . mutate ( {
4667 url : "/api/AddAutopilotConfig" ,
4768 data : formData ,
48- relatedQueryKeys : [ "Autopilot Profiles" ] ,
69+ relatedQueryKeys : [ "Autopilot Profiles* " ] ,
4970 } ) ;
5071 } ;
5172
@@ -69,22 +90,32 @@ export const CippAutopilotProfileDrawer = ({
6990 onClose = { handleCloseDrawer }
7091 size = "lg"
7192 footer = {
72- < div style = { { display : "flex" , gap : "8px" , justifyContent : "flex-start" } } >
73- < Button
74- variant = "contained"
75- color = "primary"
76- onClick = { handleSubmit }
77- disabled = { createProfile . isLoading }
93+ < div >
94+ < CippApiResults apiObject = { createProfile } />
95+ < div
96+ style = { {
97+ display : "flex" ,
98+ gap : "8px" ,
99+ justifyContent : "flex-start" ,
100+ marginTop : "16px" ,
101+ } }
78102 >
79- { createProfile . isLoading
80- ? "Creating..."
81- : createProfile . isSuccess
82- ? "Create Another"
83- : "Create Profile" }
84- </ Button >
85- < Button variant = "outlined" onClick = { handleCloseDrawer } >
86- Close
87- </ Button >
103+ < Button
104+ variant = "contained"
105+ color = "primary"
106+ onClick = { handleSubmit }
107+ disabled = { createProfile . isLoading || ! isValid }
108+ >
109+ { createProfile . isLoading
110+ ? "Creating..."
111+ : createProfile . isSuccess
112+ ? "Create Another"
113+ : "Create Profile" }
114+ </ Button >
115+ < Button variant = "outlined" onClick = { handleCloseDrawer } >
116+ Close
117+ </ Button >
118+ </ div >
88119 </ div >
89120 }
90121 >
@@ -114,6 +145,7 @@ export const CippAutopilotProfileDrawer = ({
114145 name = "DisplayName"
115146 formControl = { formControl }
116147 validators = { { required : "Display Name is required" } }
148+ required = { true }
117149 />
118150 </ Grid >
119151
@@ -202,6 +234,12 @@ export const CippAutopilotProfileDrawer = ({
202234 label = "Allow White Glove OOBE"
203235 name = "allowWhiteglove"
204236 formControl = { formControl }
237+ disabled = { deploymentMode === true }
238+ helperText = {
239+ deploymentMode === true
240+ ? "White Glove is not supported with Self-deploying mode (shared devices)"
241+ : undefined
242+ }
205243 />
206244 < CippFormComponent
207245 type = "switch"
@@ -210,8 +248,6 @@ export const CippAutopilotProfileDrawer = ({
210248 formControl = { formControl }
211249 />
212250 </ Grid >
213-
214- < CippApiResults apiObject = { createProfile } />
215251 </ Grid >
216252 </ CippOffCanvas >
217253 </ >
0 commit comments