Skip to content

Commit 4b319c3

Browse files
committed
[BLD-227] Dashboard: Add Button to download snapshot as CSV file in Claim Phase UI (#7965)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refining the `ClaimConditionsForm` and enhancing the `ClaimerSelection` component by adjusting imports, improving layout, and adding functionality to download snapshot data as a CSV file. ### Detailed summary - Removed `ArrowDownToLineIcon` from `ClaimConditionsForm`. - Updated layout in `ClaimerSelection` to use a flexible column layout. - Added a button to download snapshots as CSV in `ClaimerSelection`. - Introduced `downloadSnapshotAsCSV` function to handle CSV generation and downloading. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added CSV export for Claimer snapshots with a Download button visible when a snapshot exists. - Style - Updated snapshot actions to a responsive layout (stack on small screens, inline on larger screens). - Added a distinct Download button with an icon and adjusted Edit button styling. - Removed the icon from the Save Phases button, showing text only. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent aadaf20 commit 4b319c3

File tree

2 files changed

+44
-10
lines changed
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form

2 files changed

+44
-10
lines changed

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/Inputs/ClaimerSelection.tsx

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { UploadIcon } from "lucide-react";
1+
import { ArrowDownToLineIcon, UploadIcon } from "lucide-react";
2+
import Papa from "papaparse";
3+
import { handleDownload } from "@/components/blocks/download-file-button";
24
import { FormFieldSetup } from "@/components/blocks/FormFieldSetup";
35
import { Button } from "@/components/ui/button";
46
import {
@@ -9,6 +11,7 @@ import {
911
SelectValue,
1012
} from "@/components/ui/select";
1113
import { cn } from "@/lib/utils";
14+
import type { SnapshotEntry } from "../../legacy-zod-schema";
1215
import { useClaimConditionsFormContext } from "../index";
1316

1417
/**
@@ -118,10 +121,10 @@ export const ClaimerSelection = () => {
118121

119122
{/* Edit or See Snapshot */}
120123
{snapshot ? (
121-
<div className="flex items-center gap-3">
124+
<div className="flex flex-col md:flex-row md:items-center gap-3">
122125
{/* disable the "Edit" button when form is disabled, but not when it's a "See" button */}
123126
<Button
124-
className="gap-2 rounded-md"
127+
className="gap-2"
125128
disabled={disabledSnapshotButton}
126129
onClick={() => setOpenIndex(phaseIndex)}
127130
size="sm"
@@ -130,6 +133,21 @@ export const ClaimerSelection = () => {
130133
<UploadIcon className="size-4" />
131134
</Button>
132135

136+
{snapshot && snapshot.length > 0 && (
137+
<Button
138+
className="gap-2 rounded bg-background"
139+
variant="outline"
140+
disabled={disabledSnapshotButton}
141+
onClick={() => {
142+
downloadSnapshotAsCSV(snapshot);
143+
}}
144+
size="sm"
145+
>
146+
<ArrowDownToLineIcon className="size-4" />
147+
Download
148+
</Button>
149+
)}
150+
133151
<div
134152
className={cn(
135153
"flex gap-2 items-center",
@@ -151,3 +169,25 @@ export const ClaimerSelection = () => {
151169
</FormFieldSetup>
152170
);
153171
};
172+
173+
function downloadSnapshotAsCSV(snapshot: SnapshotEntry[]) {
174+
const csvData = snapshot.map((entry) => ({
175+
address: entry.address,
176+
maxClaimable:
177+
entry.maxClaimable === "0" ? "" : entry.maxClaimable?.toString() || "",
178+
price: entry.price?.toString() || "",
179+
currencyAddress: entry.currencyAddress || "",
180+
}));
181+
182+
const csvContent = Papa.unparse(csvData, {
183+
header: true,
184+
delimiter: ",",
185+
quotes: false,
186+
});
187+
188+
handleDownload({
189+
fileContent: csvContent,
190+
fileNameWithExtension: "snapshot.csv",
191+
fileFormat: "text/csv",
192+
});
193+
}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/claim-conditions/claim-conditions-form/index.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
"use client";
22

3-
import {
4-
ArrowDownToLineIcon,
5-
CircleAlertIcon,
6-
CircleHelpIcon,
7-
PlusIcon,
8-
} from "lucide-react";
3+
import { CircleAlertIcon, CircleHelpIcon, PlusIcon } from "lucide-react";
94
import {
105
createContext,
116
Fragment,
@@ -652,7 +647,6 @@ export const ClaimConditionsForm: React.FC<ClaimConditionsFormProps> = ({
652647
txChainID={contract.chain.id}
653648
type="submit"
654649
>
655-
<ArrowDownToLineIcon className="size-3.5" />
656650
{claimConditionsQuery.isPending
657651
? "Saving Phases"
658652
: "Save Phases"}

0 commit comments

Comments
 (0)