Skip to content

Commit

Permalink
improve modal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandSchtroumpf committed Dec 17, 2024
1 parent 5fad4a4 commit ab26ba0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/components/activity/ActivityExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { carbonApi } from 'utils/carbonApi';
import { useTokens } from 'hooks/useTokens';
import { toActivities } from './useActivityQuery';
import { MouseEvent, useRef, useState } from 'react';
import { Button } from 'components/common/button';

export const getActivityCSV = (activities: Activity[]) => {
const header = [
Expand Down Expand Up @@ -76,12 +77,10 @@ export const ActivityExport = () => {
const close = (e: MouseEvent<HTMLDialogElement>) => {
if (e.target !== e.currentTarget) return;
e.currentTarget.close();
setLoading(false);
};

const download = async () => {
setLoading(true);
if (size && size > limit) ref.current?.showModal();
const data = await carbonApi.getActivity({
...queryParams,
offset: 0,
Expand All @@ -94,11 +93,17 @@ export const ActivityExport = () => {
anchor.click();
setLoading(false);
};

const shouldDownload = () => {
if (size && size > limit) ref.current?.showModal();
else download();
};

return (
<>
<button
type="button"
onClick={download}
onClick={shouldDownload}
disabled={loading}
className="border-background-800 text-12 hover:border-background-700 hover:bg-background-800 flex items-center gap-8 rounded-full border-2 px-12 py-8 disabled:pointer-events-none disabled:opacity-60"
>
Expand All @@ -109,14 +114,20 @@ export const ActivityExport = () => {
<dialog className="modal" ref={ref} onClick={close}>
<form method="dialog" className="grid gap-16">
<p>
The Export is limited to 10.000 transactions.
<br />
Consider changing the filters
This request exceeds the maximum export limit of 10,000.&nbps;
<b>Only the first 10,000 records</b> in the selected range will be
exported.
</p>
<p>
Consider adjusting the filters to only include specific dates or
trade activity.
</p>
<hr className="border-1 border-t-white/60" />
<button type="submit" value="">
Ok
</button>
<footer className="flex gap-16">
<Button variant="success" onClick={download}>
Proceed
</Button>
<Button variant="secondary">Cancel</Button>
</footer>
</form>
</dialog>
)}
Expand Down
1 change: 1 addition & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ dialog.modal form {
@apply bg-background-900;
border-radius: 8px;
padding: 16px;
max-width: 390px;
transition: transform 0.3s var(--ease-out);
}
dialog.modal::backdrop {
Expand Down

0 comments on commit ab26ba0

Please sign in to comment.