Skip to content

fix(site): Fix template icon field validation #7394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor edit group
  • Loading branch information
BrunoQuaresma committed May 4, 2023
commit 7ea15a3d57a6625a3c3937b7a07d5a9df552a822
4 changes: 2 additions & 2 deletions site/src/pages/GroupsPage/SettingsGroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const SettingsGroupPage: FC = () => {
onUpdate: navigateToGroup,
},
})
const { updateGroupFormErrors, group } = editState.context
const { error, group } = editState.context

return (
<>
Expand All @@ -40,7 +40,7 @@ export const SettingsGroupPage: FC = () => {
sendEditEvent({ type: "UPDATE", data })
}}
group={group}
formErrors={updateGroupFormErrors}
formErrors={error}
isLoading={editState.matches("loading")}
isUpdating={editState.matches("updating")}
/>
Expand Down
36 changes: 7 additions & 29 deletions site/src/xServices/groups/editGroupXService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { getGroup, patchGroup } from "api/api"
import {
ApiError,
getErrorMessage,
hasApiFieldErrors,
isApiError,
mapApiErrorToFieldErrors,
} from "api/errors"
import { getErrorMessage } from "api/errors"
import { Group } from "api/typesGenerated"
import { displayError } from "components/GlobalSnackbar/utils"
import { assign, createMachine } from "xstate"
Expand All @@ -17,7 +11,7 @@ export const editGroupMachine = createMachine(
context: {} as {
groupId: string
group?: Group
updateGroupFormErrors?: unknown
error?: unknown
},
services: {} as {
loadGroup: {
Expand Down Expand Up @@ -61,26 +55,15 @@ export const editGroupMachine = createMachine(
onDone: {
actions: ["onUpdate"],
},
onError: [
{
target: "idle",
cond: "hasFieldErrors",
actions: ["assignUpdateGroupFormErrors"],
},
{
target: "idle",
actions: ["displayUpdateGroupError"],
},
],
onError: {
target: "idle",
actions: ["assignError"],
},
},
},
},
},
{
guards: {
hasFieldErrors: (_, event) =>
isApiError(event.data) && hasApiFieldErrors(event.data),
},
services: {
loadGroup: ({ groupId }) => getGroup(groupId),

Expand All @@ -104,12 +87,7 @@ export const editGroupMachine = createMachine(
const message = getErrorMessage(data, "Failed to the group.")
displayError(message)
},
displayUpdateGroupError: (_, { data }) => {
const message = getErrorMessage(data, "Failed to update the group.")
displayError(message)
},
assignUpdateGroupFormErrors: (_, event) =>
mapApiErrorToFieldErrors((event.data as ApiError).response.data),
assignError: (_, event) => event.data,
},
},
)