Skip to content

Commit

Permalink
feat: add AWS S3 bucket as "Send" destination for staging envs only (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Apr 9, 2024
1 parent 8900e4c commit 41a41fd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
26 changes: 23 additions & 3 deletions editor.planx.uk/src/@planx/components/Send/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ const SendComponent: React.FC<Props> = (props) => {
},
];

// Show S3 option on staging only
if (process.env.REACT_APP_ENV !== "production") {
options.push({
value: Destination.S3,
label: "Upload to AWS S3 bucket",
});
}

const changeCheckbox = (value: Destination) => (_checked: any) => {
let newCheckedValues: Destination[];

Expand All @@ -76,7 +84,8 @@ const SendComponent: React.FC<Props> = (props) => {

// Show warnings on selection of BOPS or Uniform for likely unsupported services
// Don't actually restrict selection because flowSlug matching is imperfect for some valid test cases
const flowSlug = window.location.pathname?.split("/")?.[1];
const teamSlug = window.location.pathname?.split("/")?.[1];
const flowSlug = window.location.pathname?.split("/")?.[2];
if (
value === Destination.BOPS &&
newCheckedValues.includes(value) &&
Expand All @@ -94,10 +103,21 @@ const SendComponent: React.FC<Props> = (props) => {
if (
value === Destination.Uniform &&
newCheckedValues.includes(value) &&
flowSlug !== "apply-for-a-lawful-development-certificate"
flowSlug !== "apply-for-a-lawful-development-certificate" &&
!["buckinghamshire", "lambeth", "southwark"].includes(teamSlug)
) {
alert(
"Uniform is only enabled for Bucks, Lambeth and Southwark to accept Lawful Development Certificate submissions. Please do not select if you're building another type of submission service!",
);
}

if (
value === Destination.S3 &&
newCheckedValues.includes(value) &&
teamSlug !== "barnet"
) {
alert(
"Uniform only accepts Lawful Development Certificate submissions. Please do not select if you're building another type of submission service!",
"AWS S3 uploads are currently being prototyped with Barnet only. Please do not select this option for other councils yet.",
);
}
};
Expand Down
10 changes: 10 additions & 0 deletions editor.planx.uk/src/@planx/components/Send/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ const SendComponent: React.FC<Props> = ({
makeData(props, request.value.email?.event_id, "emailSendEventId"),
);
}

if (
destinations.includes(Destination.S3) &&
isReady &&
props.handleSubmit
) {
props.handleSubmit(
makeData(props, request.value.s3?.event_id, "s3SendEventId"),
);
}
}, [request.loading, request.error, request.value]);

if (request.loading) {
Expand Down
8 changes: 8 additions & 0 deletions editor.planx.uk/src/@planx/components/Send/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum Destination {
BOPS = "bops",
Uniform = "uniform",
Email = "email",
S3 = "s3",
}

export interface Send extends MoreInformation {
Expand Down Expand Up @@ -71,5 +72,12 @@ export function getCombinedEventsPayload({
};
}

if (destinations.includes(Destination.S3)) {
combinedEventsPayload[Destination.S3] = {
localAuthority: teamSlug,
body: { sessionId },
};
}

return combinedEventsPayload;
}

0 comments on commit 41a41fd

Please sign in to comment.