Skip to content

Commit ee6579b

Browse files
committed
move date picker quick select buttons to footer
1 parent 82b7963 commit ee6579b

1 file changed

Lines changed: 70 additions & 79 deletions

File tree

packages/app/src/components/ui/date-range-picker.tsx

Lines changed: 70 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -189,69 +189,6 @@ export function DateRangePicker({
189189
)}
190190
</DialogDescription>
191191
</DialogHeader>
192-
{availableDates && availableDates.length >= 2 && (
193-
<div className="flex flex-wrap gap-2">
194-
{[
195-
{
196-
label: 'Max Range',
197-
getRange: () => ({
198-
startDate: availableDates[0],
199-
endDate: availableDates[availableDates.length - 1],
200-
}),
201-
},
202-
{
203-
label: 'Last 30 Days',
204-
getRange: () => {
205-
const cutoff = new Date();
206-
cutoff.setDate(cutoff.getDate() - 30);
207-
const cutoffStr = cutoff.toISOString().slice(0, 10);
208-
const filtered = availableDates.filter((d) => d >= cutoffStr);
209-
if (filtered.length < 2) return null;
210-
return { startDate: filtered[0], endDate: filtered[filtered.length - 1] };
211-
},
212-
},
213-
{
214-
label: 'Last 60 Days',
215-
getRange: () => {
216-
const cutoff = new Date();
217-
cutoff.setDate(cutoff.getDate() - 60);
218-
const cutoffStr = cutoff.toISOString().slice(0, 10);
219-
const filtered = availableDates.filter((d) => d >= cutoffStr);
220-
if (filtered.length < 2) return null;
221-
return { startDate: filtered[0], endDate: filtered[filtered.length - 1] };
222-
},
223-
},
224-
{
225-
label: 'Last 90 Days',
226-
getRange: () => {
227-
const cutoff = new Date();
228-
cutoff.setDate(cutoff.getDate() - 90);
229-
const cutoffStr = cutoff.toISOString().slice(0, 10);
230-
const filtered = availableDates.filter((d) => d >= cutoffStr);
231-
if (filtered.length < 2) return null;
232-
return { startDate: filtered[0], endDate: filtered[filtered.length - 1] };
233-
},
234-
},
235-
].map(({ label, getRange }) => {
236-
const range = getRange();
237-
if (!range) return null;
238-
return (
239-
<Button
240-
key={label}
241-
variant="outline"
242-
size="sm"
243-
className="text-xs h-7"
244-
onClick={() => {
245-
setTempRange(range);
246-
track('date_range_picker_quick_select', { label });
247-
}}
248-
>
249-
{label}
250-
</Button>
251-
);
252-
})}
253-
</div>
254-
)}
255192
<div className="py-4 relative">
256193
<CalendarGrid
257194
dateRange={tempRange}
@@ -299,23 +236,77 @@ export function DateRangePicker({
299236
)}
300237
</div>
301238
{error && <p className="text-md text-center text-red-500">{error}</p>}
302-
<DialogFooter>
303-
<DialogClose asChild>
304-
<Button variant="outline" onClick={handleCancel}>
305-
Cancel
239+
<DialogFooter className="flex-row justify-between sm:justify-between">
240+
{availableDates && availableDates.length >= 2 ? (
241+
<div className="flex flex-wrap gap-1.5">
242+
{[
243+
{
244+
label: 'Max Range',
245+
getRange: () => ({
246+
startDate: availableDates[0],
247+
endDate: availableDates[availableDates.length - 1],
248+
}),
249+
},
250+
{
251+
label: 'Last 90 Days',
252+
getRange: () => {
253+
const cutoff = new Date();
254+
cutoff.setDate(cutoff.getDate() - 90);
255+
const cutoffStr = cutoff.toISOString().slice(0, 10);
256+
const filtered = availableDates.filter((d) => d >= cutoffStr);
257+
if (filtered.length < 2) return null;
258+
return { startDate: filtered[0], endDate: filtered[filtered.length - 1] };
259+
},
260+
},
261+
{
262+
label: 'Last 30 Days',
263+
getRange: () => {
264+
const cutoff = new Date();
265+
cutoff.setDate(cutoff.getDate() - 30);
266+
const cutoffStr = cutoff.toISOString().slice(0, 10);
267+
const filtered = availableDates.filter((d) => d >= cutoffStr);
268+
if (filtered.length < 2) return null;
269+
return { startDate: filtered[0], endDate: filtered[filtered.length - 1] };
270+
},
271+
},
272+
].map(({ label, getRange }) => {
273+
const range = getRange();
274+
if (!range) return null;
275+
return (
276+
<Button
277+
key={label}
278+
variant="outline"
279+
onClick={() => {
280+
setTempRange(range);
281+
track('date_range_picker_quick_select', { label });
282+
}}
283+
>
284+
{label}
285+
</Button>
286+
);
287+
})}
288+
</div>
289+
) : (
290+
<div />
291+
)}
292+
<div className="flex gap-2">
293+
<DialogClose asChild>
294+
<Button variant="outline" onClick={handleCancel}>
295+
Cancel
296+
</Button>
297+
</DialogClose>
298+
<Button
299+
onClick={handleApply}
300+
disabled={
301+
!tempRange.startDate ||
302+
!tempRange.endDate ||
303+
isApplying ||
304+
(availableDates !== undefined && availableDates.length < 2)
305+
}
306+
>
307+
{isApplying ? 'Applying...' : 'Apply'}
306308
</Button>
307-
</DialogClose>
308-
<Button
309-
onClick={handleApply}
310-
disabled={
311-
!tempRange.startDate ||
312-
!tempRange.endDate ||
313-
isApplying ||
314-
(availableDates !== undefined && availableDates.length < 2)
315-
}
316-
>
317-
{isApplying ? 'Applying...' : 'Apply'}
318-
</Button>
309+
</div>
319310
</DialogFooter>
320311
</DialogContent>
321312
</Dialog>

0 commit comments

Comments
 (0)