UI - remove fancy error state logic on team settings (#17356)

## Updates feature per
https://github.com/fleetdm/fleet/pull/17285#issuecomment-1977457175
https://www.loom.com/share/c10941c7e2e74b4cb55c31427e0f5886
- [x] Manual QA for all new/changed functionality

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
Jacob Shandling 2024-03-04 15:08:30 -08:00 committed by GitHub
parent 2991e08ecc
commit d477369ed3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -54,8 +54,7 @@ const HOST_EXPIRY_ERROR_TEXT = "Host expiry window must be a positive number.";
const validateTeamSettingsFormData = (
// will never be called if global setting is not loaded, default to satisfy typechecking
curGlobalHostExpiryEnabled = false,
curFormData: ITeamSettingsFormData,
prevFormData?: ITeamSettingsFormData
curFormData: ITeamSettingsFormData
) => {
const errors: Record<string, string> = {};
@ -76,23 +75,11 @@ const validateTeamSettingsFormData = (
// validate host webhook fields
if (curFormData.teamHostStatusWebhookEnabled) {
const userJustEnabledWebhook =
!!prevFormData &&
!prevFormData?.teamHostStatusWebhookEnabled &&
curFormData.teamHostStatusWebhookEnabled;
const shouldNotError =
userJustEnabledWebhook &&
!curFormData.teamHostStatusWebhookDestinationUrl;
// if the user just enabled the webhook, don't show an error until they've entered a URL or tried to submit the form without one
if (
!shouldNotError &&
!validURL({ url: curFormData.teamHostStatusWebhookDestinationUrl })
) {
if (!validURL({ url: curFormData.teamHostStatusWebhookDestinationUrl })) {
const errorPrefix = curFormData.teamHostStatusWebhookDestinationUrl
? `${curFormData.teamHostStatusWebhookDestinationUrl} is not`
: "Please enter";
errors.host_status_webhook_destination_url = `${errorPrefix} a valid URL`;
errors.host_status_webhook_destination_url = `${errorPrefix} a valid webhook destination URL`;
}
}
@ -190,18 +177,10 @@ const TeamSettings = ({ location, router }: ITeamSubnavProps) => {
const onInputChange = useCallback(
(newVal: { name: FormNames; value: string | number | boolean }) => {
const { name, value } = newVal;
// these are compared to determine if the user just enabled the webhook
const [newFormData, prevFormData] = [
{ ...formData, [name]: value },
{ ...formData },
];
const newFormData = { ...formData, [name]: value };
setFormData(newFormData);
setFormErrors(
validateTeamSettingsFormData(
globalHostExpiryEnabled,
newFormData,
prevFormData
)
validateTeamSettingsFormData(globalHostExpiryEnabled, newFormData)
);
},
[formData, globalHostExpiryEnabled]
@ -211,15 +190,6 @@ const TeamSettings = ({ location, router }: ITeamSubnavProps) => {
(evt: React.MouseEvent<HTMLFormElement>) => {
evt.preventDefault();
const errors = validateTeamSettingsFormData(
globalHostExpiryEnabled,
formData
);
if (Object.keys(errors).length > 0) {
setFormErrors(errors);
return;
}
setUpdatingTeamSettings(true);
const castedHostExpiryWindow = Number(formData.teamHostExpiryWindow);
let enableHostExpiry;