-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COM-962: Improve UI/UX of target group page (#64)
* add dialog for creating a new target group * add filter * set filters to optional and assign contacts only if a filter is given * fix prettier errors * simplify onSubmit * rename FormProps to TargetGroupDialogProps * use EditDialog from comet * remove create from TargetGroupForm as it is not possible to create a new TargetGroup here * fix EditDialog to not redirect back to grid * set id to required and remove conditions where id is not given * remove Stackpage for adding a targetGroup as this page doesn't exist anymore --------- Co-authored-by: Julia Wegmayr <[email protected]>
- Loading branch information
1 parent
34beaac
commit 1fc8d9d
Showing
7 changed files
with
138 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { gql } from "@apollo/client"; | ||
|
||
export const createTargetGroupMutation = gql` | ||
mutation CreateTargetGroup($scope: EmailCampaignContentScopeInput!, $input: TargetGroupInput!) { | ||
createTargetGroup(scope: $scope, input: $input) { | ||
id | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useApolloClient } from "@apollo/client"; | ||
import { Field, FinalForm, FinalFormInput, FinalFormSubmitEvent, useStackSwitchApi } from "@comet/admin"; | ||
import { ContentScopeInterface } from "@comet/cms-admin"; | ||
import { FormApi } from "final-form"; | ||
import React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import { createTargetGroupMutation } from "./TargetGroupDialog.gql"; | ||
import { GQLCreateTargetGroupMutation, GQLCreateTargetGroupMutationVariables } from "./TargetGroupDialog.gql.generated"; | ||
import { EditTargetGroupFinalFormValues } from "./TargetGroupForm"; | ||
|
||
interface TargetGroupDialogProps { | ||
scope: ContentScopeInterface; | ||
} | ||
|
||
export function TargetGroupDialog({ scope }: TargetGroupDialogProps): React.ReactElement { | ||
const client = useApolloClient(); | ||
const mode = "add"; | ||
const stackSwitchApi = useStackSwitchApi(); | ||
|
||
const handleSubmit = async ( | ||
state: EditTargetGroupFinalFormValues, | ||
form: FormApi<EditTargetGroupFinalFormValues>, | ||
event: FinalFormSubmitEvent, | ||
) => { | ||
const output = { | ||
...state, | ||
}; | ||
|
||
const { data: mutationResponse } = await client.mutate<GQLCreateTargetGroupMutation, GQLCreateTargetGroupMutationVariables>({ | ||
mutation: createTargetGroupMutation, | ||
variables: { scope, input: output }, | ||
}); | ||
if (!event.navigatingBack) { | ||
const id = mutationResponse?.createTargetGroup.id; | ||
if (id) { | ||
setTimeout(() => { | ||
stackSwitchApi.activatePage("edit", id); | ||
}); | ||
} | ||
} | ||
}; | ||
return ( | ||
<FinalForm<EditTargetGroupFinalFormValues> onSubmit={handleSubmit} mode={mode}> | ||
{() => { | ||
return ( | ||
<Field | ||
required | ||
fullWidth | ||
name="title" | ||
component={FinalFormInput} | ||
label={<FormattedMessage id="cometBrevoModule.targetGroup.title" defaultMessage="Title" />} | ||
/> | ||
); | ||
}} | ||
</FinalForm> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters