Skip to content
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

refactor(export-campaign): extract payload types #44

Merged
merged 9 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions libs/gql-schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ const rootSchema = `

input CampaignExportInput {
campaignId: String!
# For Spoke Exports
campaignTitle: String
exportType: CampaignExportType!
spokeOptions: ExportForSpokeInput
vanOptions: ExportForVanInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ import React, { useState } from "react";
interface CampaignExportModalProps {
open: boolean;
campaignId: string;
campaignTitle: string;
onError(errorMessage: string): void;
onClose(): void;
onComplete(): void;
}

const CampaignExportModal: React.FC<CampaignExportModalProps> = (props) => {
const { campaignId, open, onClose, onComplete, onError } = props;
const {
campaignId,
campaignTitle,
open,
onClose,
onComplete,
onError
} = props;
const [exportCampaign, setExportCampaign] = useState<boolean>(true);
const [exportMessages, setExportMessages] = useState<boolean>(true);
const [exportOptOut, setExportOptOut] = useState<boolean>(false);
Expand All @@ -39,6 +47,7 @@ const CampaignExportModal: React.FC<CampaignExportModalProps> = (props) => {
variables: {
options: {
campaignId,
campaignTitle,
exportType: CampaignExportType.Spoke,
spokeOptions: {
campaign: exportCampaign,
Expand Down
13 changes: 1 addition & 12 deletions src/containers/AdminCampaignStats/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class AdminCampaignStats extends React.Component {
/>
<CampaignExportModal
campaignId={campaignId}
campaignTitle={campaign.title}
open={this.state.exportDialogOpen}
onClose={this.handleCloseCampaignExport}
onComplete={this.handleCompleteCampaignExport}
Expand Down Expand Up @@ -536,18 +537,6 @@ const mutations = {
`,
variables: { campaignId: ownProps.match.params.campaignId }
}),
exportCampaign: (ownProps) => () => ({
mutation: gql`
mutation exportCampaign($campaignId: String!) {
exportCampaign(
options: { campaignId: $campaignId, exportType: SPOKE }
) {
id
}
}
`,
variables: { campaignId: ownProps.match.params.campaignId }
}),
copyCampaign: (ownProps) => () => ({
mutation: gql`
mutation copyCampaign($campaignId: String!) {
Expand Down
2 changes: 2 additions & 0 deletions src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ input ExportForSpokeInput {

input CampaignExportInput {
campaignId: String!
# For Spoke Exports
campaignTitle: String
exportType: CampaignExportType!
spokeOptions: ExportForSpokeInput
vanOptions: ExportForVanInput
Expand Down
11 changes: 9 additions & 2 deletions src/server/api/root-mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import MemoizeHelper, { cacheOpts } from "../memoredis";
import { cacheableData, r } from "../models";
import { getUserById } from "../models/cacheable_queries";
import { Notifications, sendUserNotification } from "../notifications";
import { addExportCampaign } from "../tasks/export-campaign";
import { addExportCampaign } from "../tasks/chunk-tasks/export-campaign";
import { addExportForVan } from "../tasks/export-for-van";
import { TASK_IDENTIFIER as exportOptOutsIdentifier } from "../tasks/export-opt-outs";
import { addFilterLandlines } from "../tasks/filter-landlines";
Expand Down Expand Up @@ -296,7 +296,13 @@ const rootMutations = {
},

exportCampaign: async (_root, { options }, { user, loaders }) => {
const { campaignId, exportType, vanOptions, spokeOptions } = options;
const {
campaignId,
campaignTitle,
exportType,
vanOptions,
spokeOptions
} = options;

if (exportType === CampaignExportType.VAN && !vanOptions) {
throw new Error("Input must include vanOptions when exporting as VAN!");
Expand All @@ -313,6 +319,7 @@ const rootMutations = {
if (exportType === CampaignExportType.SPOKE) {
return addExportCampaign({
campaignId,
campaignTitle,
requesterId: user.id,
spokeOptions
});
Expand Down
Loading
Loading