Skip to content

Commit b994c62

Browse files
committed
update csv filename to reflect filters and time stamp
1 parent a625196 commit b994c62

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

pages/payments/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,18 @@ export default function Payments ({ user, userId }: PaybuttonsProps): React.Reac
225225
throw new Error('Failed to download CSV')
226226
}
227227

228-
const fileName = `${isCurrencyEmptyOrUndefined(currency) ? 'all' : `${currency.toLowerCase()}`}-transactions`
228+
const selectedButtonNames = buttons
229+
.filter(btn => selectedButtonIds.includes(btn.id))
230+
.map(btn => btn.name.replace(/\s+/g, '-'))
231+
.join('_')
232+
233+
const buttonSuffix = selectedButtonIds.length > 0
234+
? `-${selectedButtonNames !== '' ? selectedButtonNames : 'filtered'}`
235+
: ''
236+
const currencyLabel = isCurrencyEmptyOrUndefined(currency) ? 'all' : currency.toLowerCase()
237+
const timestamp = moment().format('YYYY-MM-DD_HH-mm-ss')
238+
239+
const fileName = `${currencyLabel}-transactions${buttonSuffix}-${timestamp}`
229240
const blob = await response.blob()
230241
const downloadUrl = window.URL.createObjectURL(blob)
231242
const link = document.createElement('a')

0 commit comments

Comments
 (0)