Skip to content

Commit

Permalink
COM-977 Fix: adapt TargetGroupForm to allow removed filters (#77)
Browse files Browse the repository at this point in the history
* adapt TargetGroupForm to allow removed filters

* add changeset

* add check for nodeFragment to make code more readable

---------

Co-authored-by: Julia Wegmayr <[email protected]>
  • Loading branch information
juliawegmayr and juliawegmayr authored Aug 26, 2024
1 parent e5dbbfa commit be70f36
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-buses-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/brevo-admin": minor
---

Fix `TargetGroupForms` if no additional form fields are defined.
66 changes: 36 additions & 30 deletions packages/admin/src/targetGroups/TargetGroupForm.gql.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { DocumentNode, gql } from "@apollo/client";

export const targetGroupFormQuery = (targetGroupFormFragment: DocumentNode) => gql`
query TargetGroupForm($id: ID!) {
targetGroup(id: $id) {
id
title
updatedAt
brevoId
assignedContactsTargetGroupBrevoId
...TargetGroupForm
export const targetGroupFormQuery = (targetGroupFormFragment?: DocumentNode) => {
return gql`
query TargetGroupForm($id: ID!) {
targetGroup(id: $id) {
id
title
updatedAt
brevoId
assignedContactsTargetGroupBrevoId
${targetGroupFormFragment ? "...TargetGroupForm" : ""}
}
}
}
${targetGroupFormFragment}
`;
${targetGroupFormFragment ?? ""}
`;
};

export const targetGroupFormCheckForChangesQuery = gql`
query TargetGroupFormCheckForChanges($id: ID!) {
Expand All @@ -22,24 +24,28 @@ export const targetGroupFormCheckForChangesQuery = gql`
}
`;

export const createTargetGroupMutation = (targetGroupFormFragment: DocumentNode) => gql`
mutation CreateTargetGroup($scope: EmailCampaignContentScopeInput!, $input: TargetGroupInput!) {
createTargetGroup(scope: $scope, input: $input) {
id
updatedAt
...TargetGroupForm
export const createTargetGroupMutation = (targetGroupFormFragment?: DocumentNode) => {
return gql`
mutation CreateTargetGroup($scope: EmailCampaignContentScopeInput!, $input: TargetGroupInput!) {
createTargetGroup(scope: $scope, input: $input) {
id
updatedAt
${targetGroupFormFragment ? "...TargetGroupForm" : ""}
}
}
}
${targetGroupFormFragment}
`;
${targetGroupFormFragment ?? ""}
`;
};

export const updateTargetGroupMutation = (targetGroupFormFragment: DocumentNode) => gql`
mutation UpdateTargetGroup($id: ID!, $input: TargetGroupUpdateInput!, $lastUpdatedAt: DateTime) {
updateTargetGroup(id: $id, input: $input, lastUpdatedAt: $lastUpdatedAt) {
id
updatedAt
...TargetGroupForm
export const updateTargetGroupMutation = (targetGroupFormFragment?: DocumentNode) => {
return gql`
mutation UpdateTargetGroup($id: ID!, $input: TargetGroupUpdateInput!, $lastUpdatedAt: DateTime) {
updateTargetGroup(id: $id, input: $input, lastUpdatedAt: $lastUpdatedAt) {
id
updatedAt
${targetGroupFormFragment ? "...TargetGroupForm" : ""}
}
}
}
${targetGroupFormFragment}
`;
${targetGroupFormFragment ?? ""}
`;
};
15 changes: 9 additions & 6 deletions packages/admin/src/targetGroups/TargetGroupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ export function TargetGroupForm({ id, scope, additionalFormFields, input2State,
const mode = "edit";
const formApiRef = useFormApiRef<EditTargetGroupFinalFormValues>();

const targetGroupFormFragment = gql`
fragment TargetGroupForm on TargetGroup {
${nodeFragment ? "...".concat(nodeFragment?.name) : ""}
}
${nodeFragment?.fragment ?? ""}
`;
let targetGroupFormFragment: DocumentNode | undefined;
if (additionalFormFields && nodeFragment) {
targetGroupFormFragment = gql`
fragment TargetGroupForm on TargetGroup {
${"...".concat(nodeFragment.name)}
}
${nodeFragment.fragment}
`;
}

const { data, error, loading, refetch } = useQuery<GQLTargetGroupFormQuery, GQLTargetGroupFormQueryVariables>(
targetGroupFormQuery(targetGroupFormFragment),
Expand Down

0 comments on commit be70f36

Please sign in to comment.