Skip to content

Commit

Permalink
fix: date formatting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Billie He committed Oct 17, 2024
1 parent 35af938 commit 09ec4bc
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/entities/activity/ui/items/PhrasalTemplateItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo, useContext, useCallback, useRef, useState } from 'react';

import { Avatar, Button } from '@mui/material';
import { format as formatDate } from 'date-fns';
import { isMobile } from 'react-device-detect';
import { v4 as uuidV4 } from 'uuid';

Expand Down Expand Up @@ -29,23 +30,20 @@ export const PhrasalTemplateItem = ({ item, replaceText }: PhrasalTemplateItemPr
const documentIdRef = useRef<string>(uuidV4());
const { t } = usePhrasalTemplateTranslation();

const handleDownloadImage = useCallback(async () => {
const now = new Date();
const filename = [
appletDisplayName,
phrasalTemplateCardTitle,
String(now.getMonth() + 1).padStart(2, '0'),
String(now.getDate()).padStart(2, '0'),
now.getFullYear(),
].join('_');

await downloadPhrasalTemplateItem({
documentId: documentIdRef.current,
filename,
share: isMobile,
single: false,
});
}, [appletDisplayName, phrasalTemplateCardTitle]);
const handleDownloadImage = useCallback(
async () =>
await downloadPhrasalTemplateItem({
documentId: documentIdRef.current,
filename: [
appletDisplayName,
phrasalTemplateCardTitle,
formatDate(new Date(), 'MM_dd_yyyy'),
].join('_'),
share: isMobile,
single: false,
}),
[appletDisplayName, phrasalTemplateCardTitle],
);

return (
<Box gap="24px" display={'flex'} flexDirection={'column'} alignItems="center">
Expand Down

0 comments on commit 09ec4bc

Please sign in to comment.