Skip to content

Commit

Permalink
Merge pull request #31 from vivid-planet/do-not-allow-edit-of-main-ta…
Browse files Browse the repository at this point in the history
…rget-group

COM-271: Do not allow edit of main target group
  • Loading branch information
RainbowBunchie authored Jan 30, 2024
2 parents 4339960 + 9799fd9 commit 1a7ba40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/admin/src/targetGroups/TargetGroupsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const targetGroupsFragment = gql`
title
totalSubscribers
totalContactsBlocked
isMainList
}
`;

Expand Down Expand Up @@ -123,15 +124,15 @@ export function TargetGroupsGrid({ scope }: { scope: ContentScopeInterface }): R
sortable: false,
filterable: false,
type: "actions",
renderCell: (params) => {
renderCell: ({ row }) => {
if (row.isMainList) return;
return (
<>
<IconButton component={StackLink} pageName="edit" payload={params.row.id}>
<IconButton component={StackLink} pageName="edit" payload={row.id}>
<Edit color="primary" />
</IconButton>
<CrudContextMenu
copyData={() => {
const row = params.row;
return {
title: row.title,
};
Expand All @@ -145,7 +146,7 @@ export function TargetGroupsGrid({ scope }: { scope: ContentScopeInterface }): R
onDelete={async () => {
await client.mutate<GQLDeleteTargetGroupMutation, GQLDeleteTargetGroupMutationVariables>({
mutation: deleteTargetGroupMutation,
variables: { id: params.row.id },
variables: { id: row.id },
});
}}
refetchQueries={[targetGroupsQuery]}
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/target-group/target-group.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export function createTargetGroupsResolver({
): Promise<TargetGroupInterface> {
const targetGroup = await this.repository.findOneOrFail(id);

if (targetGroup.isMainList) {
throw new Error("Cannot edit a main target group");
}

if (lastUpdatedAt) {
validateNotModified(targetGroup, lastUpdatedAt);
}
Expand Down Expand Up @@ -135,6 +139,10 @@ export function createTargetGroupsResolver({
async deleteTargetGroup(@Args("id", { type: () => ID }) id: string): Promise<boolean> {
const targetGroup = await this.repository.findOneOrFail(id);

if (targetGroup.isMainList) {
throw new Error("Cannot delete a main target group");
}

const isDeletedInBrevo = await this.brevoApiContactsService.deleteBrevoContactList(targetGroup.brevoId);

if (!isDeletedInBrevo) {
Expand Down

0 comments on commit 1a7ba40

Please sign in to comment.