Skip to content

Commit e6d5d16

Browse files
committed
integrate deactivate link functionality with UI
1 parent 7198697 commit e6d5d16

File tree

3 files changed

+63
-31
lines changed

3 files changed

+63
-31
lines changed

src/api/functions/auditLog.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ export function buildAuditLogTransactPut({
5656
}: {
5757
entry: AuditLogEntry;
5858
}): TransactWriteItem {
59-
if (process.env.DISABLE_AUDIT_LOG && process.env.RunEnvironment === "dev") {
60-
console.log(`Audit log entry: ${JSON.stringify(entry)}`);
61-
return {};
62-
}
6359
const item = buildMarshalledAuditLogItem(entry);
6460
return {
6561
Put: {

src/ui/pages/stripe/CurrentLinks.tsx

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,49 @@ const HumanFriendlyDate = ({ date }: { date: string | Date }) => {
2525

2626
interface StripeCurrentLinksPanelProps {
2727
getLinks: () => Promise<GetInvoiceLinksResponse>;
28+
deactivateLink: (linkId: string) => Promise<void>;
2829
}
2930

3031
export const StripeCurrentLinksPanel: React.FC<
3132
StripeCurrentLinksPanelProps
32-
> = ({ getLinks }) => {
33+
> = ({ getLinks, deactivateLink }) => {
3334
const [links, setLinks] = useState<GetInvoiceLinksResponse | null>(null);
3435
const [isLoading, setIsLoading] = useState<boolean>(true);
3536
const [selectedRows, setSelectedRows] = useState<string[]>([]);
3637
const { userData } = useAuth();
37-
useEffect(() => {
38-
const getLinksOnLoad = async () => {
39-
try {
40-
setIsLoading(true);
41-
const data = await getLinks();
42-
setLinks(data);
43-
setIsLoading(false);
44-
} catch (e) {
45-
setIsLoading(false);
46-
notifications.show({
47-
title: "Error",
48-
message:
49-
"Failed to get payment links. Please try again or contact support.",
50-
color: "red",
51-
icon: <IconAlertCircle size={16} />,
52-
});
53-
console.error(e);
38+
const deleteLinks = async (linkIds: string[]) => {
39+
const promises = linkIds.map((x) => deactivateLink(x));
40+
const results = await Promise.allSettled(promises);
41+
let success = 0;
42+
let fail = 0;
43+
for (const item of results) {
44+
if (item.status === "rejected") {
45+
fail++;
46+
} else {
47+
success++;
5448
}
55-
};
49+
}
50+
return { fail, success };
51+
};
52+
const getLinksOnLoad = async () => {
53+
try {
54+
setIsLoading(true);
55+
const data = await getLinks();
56+
setLinks(data);
57+
setIsLoading(false);
58+
} catch (e) {
59+
setIsLoading(false);
60+
notifications.show({
61+
title: "Error",
62+
message:
63+
"Failed to get payment links. Please try again or contact support.",
64+
color: "red",
65+
icon: <IconAlertCircle size={16} />,
66+
});
67+
console.error(e);
68+
}
69+
};
70+
useEffect(() => {
5671
getLinksOnLoad();
5772
}, []);
5873
const createTableRow = (data: GetInvoiceLinksResponse[number]) => {
@@ -116,13 +131,27 @@ export const StripeCurrentLinksPanel: React.FC<
116131
</Table.Tr>
117132
);
118133
};
119-
const deactivateLinks = (linkIds: string[]) => {
120-
notifications.show({
121-
title: "Feature not available",
122-
message: "Coming soon!",
123-
color: "yellow",
124-
icon: <IconAlertTriangle size={16} />,
125-
});
134+
const deactivateLinks = async (linkIds: string[]) => {
135+
setIsLoading(true);
136+
try {
137+
const result = await deleteLinks(linkIds);
138+
if (result.fail > 0) {
139+
notifications.show({
140+
title: `Failed to deactivate ${pluralize("link", result.fail, true)}.`,
141+
message: "Please try again later.",
142+
color: "red",
143+
});
144+
}
145+
if (result.success > 0) {
146+
notifications.show({
147+
message: `Deactivated ${pluralize("link", result.success, true)}!`,
148+
color: "green",
149+
});
150+
}
151+
getLinksOnLoad();
152+
} finally {
153+
setIsLoading(false);
154+
}
126155
};
127156

128157
return (

src/ui/pages/stripe/ViewLinks.page.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export const ManageStripeLinksPage: React.FC = () => {
3333
return response.data;
3434
};
3535

36+
const deactivateLink = async (linkId: string): Promise<void> => {
37+
await api.delete(`/api/v1/stripe/paymentLinks/${linkId}`);
38+
};
39+
3640
return (
3741
<AuthGuard
3842
resourceDef={{
@@ -47,7 +51,10 @@ export const ManageStripeLinksPage: React.FC = () => {
4751
Create a Stripe Payment Link to accept credit card payments.
4852
</Text>
4953
<StripeCreateLinkPanel createLink={createLink} />
50-
<StripeCurrentLinksPanel getLinks={getLinks} />
54+
<StripeCurrentLinksPanel
55+
getLinks={getLinks}
56+
deactivateLink={deactivateLink}
57+
/>
5158
</Container>
5259
</AuthGuard>
5360
);

0 commit comments

Comments
 (0)