Skip to content

Commit

Permalink
refactor: use banner instead of modal for backup rp notice (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap authored Dec 6, 2024
1 parent ec541ae commit 7fa25a4
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 96 deletions.
2 changes: 2 additions & 0 deletions src/app/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as metrics from "@app/metric-tunnel";
import * as mfa from "@app/mfa";
import * as modal from "@app/modal";
import * as nav from "@app/nav";
import * as notice from "@app/notice";
import * as orgs from "@app/organizations";
import * as redirectPath from "@app/redirect-path";
import * as resetStore from "@app/reset-store";
Expand Down Expand Up @@ -56,6 +57,7 @@ const corePackages: any[] = [
source,
loaders,
modal,
notice,
];

export const rootEntities = corePackages.reduce((acc, pkg) => {
Expand Down
24 changes: 2 additions & 22 deletions src/bootup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,15 @@ import {
fetchStacks,
} from "@app/deploy";
import { fetchDeployments } from "@app/deployment";
import { call, parallel, put, select, takeEvery } from "@app/fx";
import { call, parallel, select, takeEvery } from "@app/fx";
import { createAction } from "@app/fx";
import { openModal } from "@app/modal";
import { selectOrganizationSelected } from "@app/organizations";
import { fetchCurrentUserRoles, fetchRoles } from "@app/roles";
import { schema } from "@app/schema";
import { fetchSources } from "@app/source";
import { fetchSystemStatus } from "@app/system-status";
import { selectAccessToken } from "@app/token";
import { ModalType } from "@app/types";
import {
fetchUser,
fetchUsers,
selectCurrentUser,
selectCurrentUserId,
} from "@app/users";
import { fetchUser, fetchUsers, selectCurrentUserId } from "@app/users";

export const FETCH_REQUIRED_DATA = "fetch-required-data";

Expand Down Expand Up @@ -72,7 +65,6 @@ function* onFetchRequiredData() {
yield* fetchUser.run({ userId });
const org = yield* select(selectOrganizationSelected);
yield* fetchBillingDetail.run({ id: org.billingDetailId });
yield* onCheckForNotices();

yield* schema.update(schema.loaders.success({ id: FETCH_REQUIRED_DATA }));
}
Expand Down Expand Up @@ -104,18 +96,6 @@ function* onFetchResourceData() {
yield* group;
}

function* onCheckForNotices() {
const user = yield* select(selectCurrentUser);
const createdAt = new Date(user.createdAt);
const notices = yield* select(schema.notices.select);
if (
notices["backup-rp-notice"] === "" &&
createdAt < new Date(2024, 10 - 1, 17)
) {
yield* put(openModal({ type: ModalType.BackupRPNotice, props: {} }));
}
}

function* onRefreshData() {
yield* onFetchRequiredData();
yield* onFetchResourceData();
Expand Down
15 changes: 1 addition & 14 deletions src/modal/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import { thunks } from "@app/api";
import { schema } from "@app/schema";
import type { ModalState, ModalType } from "@app/types";

export const readNotice = thunks.create<ModalType>(
"read-notice",
function* (ctx, next) {
yield* schema.update(
schema.notices.update({
key: ctx.payload,
value: new Date().toISOString(),
}),
);
yield* next();
},
);
import type { ModalState } from "@app/types";

export const openModal = thunks.create<ModalState>(
"open-modal",
Expand Down
16 changes: 16 additions & 0 deletions src/notice/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { thunks } from "@app/api";
import { schema } from "@app/schema";
import type { NoticeType } from "@app/types";

export const readNotice = thunks.create<NoticeType>(
"read-notice",
function* (ctx, next) {
yield* schema.update(
schema.notices.update({
key: ctx.payload,
value: new Date().toISOString(),
}),
);
yield* next();
},
);
7 changes: 4 additions & 3 deletions src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type ModalState,
ModalType,
type Nav,
NoticeType,
type ResourceStats,
type Role,
type U2fDevice,
Expand Down Expand Up @@ -88,9 +89,9 @@ export const [schema, initialState] = createSchema({
manualScaleRecommendations: slice.table({
empty: factory.defaultManualScaleRecommendation(),
}),
notices: slice.obj<Record<ModalType, string>>({
[ModalType.BackupRPNotice]: "",
[ModalType.NONE]: "",
notices: slice.obj<Record<NoticeType, string>>({
[NoticeType.BackupRPNotice]: "",
[NoticeType.NONE]: "",
}),
});
export type WebState = typeof initialState;
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from "./deploy";
export * from "./modal";
export * from "./api";
export * from "./auth";
export * from "./ux";
1 change: 0 additions & 1 deletion src/types/modal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export enum ModalType {
NONE = "",
BackupRPNotice = "backup-rp-notice",
}

export interface ModalState {
Expand Down
4 changes: 4 additions & 0 deletions src/types/ux.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum NoticeType {
NONE = "",
BackupRPNotice = "backup-rp-notice",
}
16 changes: 15 additions & 1 deletion src/ui/layouts/app-sidebar-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { selectNav } from "@app/nav";
import { useSelector } from "@app/react";
import { schema } from "@app/schema";
import { selectCurrentUser } from "@app/users";
import { Outlet } from "react-router";
import { ApplicationSidebar, Footer, Group } from "../shared";
import {
ApplicationSidebar,
Footer,
Group,
NoticeBackupRpBanner,
} from "../shared";

interface Props {
children?: React.ReactNode;
Expand All @@ -18,6 +25,12 @@ export function AppSidebarLayout({
}: Props) {
const { collapsed } = useSelector(selectNav);
const collapsedOffset = collapsed ? 15.2 : 64;
const user = useSelector(selectCurrentUser);
const createdAt = new Date(user.createdAt);
const notices = useSelector(schema.notices.select);
const showNotice =
notices["backup-rp-notice"] === "" &&
createdAt < new Date(2024, 10 - 1, 17);

return (
<div className={`flex h-full ${className}`}>
Expand All @@ -33,6 +46,7 @@ export function AppSidebarLayout({
>
<main className={`h-full flex flex-col ${padding ? "py-4 px-7" : ""}`}>
<Group>
{showNotice ? <NoticeBackupRpBanner /> : null}
{header ? header : null}
{children ? children : <Outlet />}
</Group>
Expand Down
1 change: 1 addition & 0 deletions src/ui/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ export * from "./us-states";
export * from "./countries";
export * from "./scale-recs";
export * from "./last-scale";
export * from "./notice";
59 changes: 4 additions & 55 deletions src/ui/shared/modal-portal.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,11 @@
import { createLog } from "@app/debug";
import { closeModal, readNotice } from "@app/modal";
import { useDispatch, useSelector } from "@app/react";
import { useSelector } from "@app/react";
import { schema } from "@app/schema";
import { ModalType } from "@app/types";
import { Button } from "./button";
import { ExternalLink } from "./external-link";
import { Group } from "./group";
import { Modal, ModalBody, ModalFooter, ModalHeading } from "./modal";

const log = createLog("modal-portal");

const BackupRPNotice = () => {
const dispatch = useDispatch();
const gotit = () => {
dispatch(readNotice(ModalType.BackupRPNotice));
dispatch(closeModal());
};

return (
<ModalWrapper>
<Modal isOpen>
<ModalHeading title="New Default Backup Retention Policy" />
<ModalBody>
<Group>
<p>
As of <span className="font-bold">07/25/2024</span>, we've changed
the default backup retention policy for newly created environments
to:
</p>
<ul className="list-disc list-inside">
<li>30 daily</li>
<li>12 monthly</li>
<li>6 yearly</li>
<li>cross-region copy: disabled</li>
<li>keep final backup: enabled</li>
</ul>
<p>
For more information,{" "}
<ExternalLink href="https://www.aptible.com/changelog/new-default-backup-retention-policy">
read the changelog.
</ExternalLink>
</p>
</Group>
</ModalBody>
<ModalFooter
actions={[
<Button key="gotit" variant="primary" onClick={gotit}>
Got it!
</Button>,
]}
/>
</Modal>
</ModalWrapper>
);
};

const ModalWrapper = ({ children }: { children: React.ReactNode }) => {
export const ModalWrapper = ({ children }: { children: React.ReactNode }) => {
return (
<div className="fixed top-0 left-0 w-screen h-screen flex justify-center items-center bg-opacity-50 bg-black z-10">
<div>{children}</div>
Expand All @@ -69,9 +19,8 @@ export const ModalPortal = () => {
log(modal);

switch (modal.type) {
case ModalType.BackupRPNotice: {
return <BackupRPNotice />;
}
case ModalType.NONE:
return null;
default:
return null;
}
Expand Down
52 changes: 52 additions & 0 deletions src/ui/shared/notice.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { readNotice } from "@app/notice";
import { NoticeType } from "@app/types";
import { useDispatch } from "starfx/react";
import { Box } from "./box";
import { Button } from "./button";
import { ExternalLink } from "./external-link";
import { Group } from "./group";
import { IconInfo } from "./icons";
import { tokens } from "./tokens";

export function NoticeBackupRpBanner() {
const dispatch = useDispatch();
const gotit = () => {
dispatch(readNotice(NoticeType.BackupRPNotice));
};

return (
<Box bg="gray-50">
<Group>
<h4 className={`${tokens.type.h4} flex gap-2 items-center`}>
<IconInfo variant="sm" />
New Backup Retention Policy
</h4>
<p>
As of <span className="font-bold">07/25/2024</span>, we've changed the
default backup retention policy for newly created environments to:
</p>
<ul className="list-disc list-inside">
<li>
<strong>30</strong> daily backups, <strong>12</strong> monthly
backups, <strong>6</strong> yearly backups
</li>
<li>
Cross-region copies: <strong>Disabled</strong>, Keep final backups:{" "}
<strong>Enabled</strong>
</li>
</ul>
<p>
For more information,{" "}
<ExternalLink href="https://www.aptible.com/changelog/new-default-backup-retention-policy">
read the changelog.
</ExternalLink>
</p>
<div>
<Button key="gotit" variant="primary" onClick={gotit}>
Got it!
</Button>
</div>
</Group>
</Box>
);
}

0 comments on commit 7fa25a4

Please sign in to comment.