type GroupeDataByDate = (arg: { filteredFiles: CustomerFile[] }) => {
[key: string]: CustomerStatusCardsProps['data'][number]['data'][number][];
};
const groupeDataByDateDefaultValue: ReturnType<GroupeDataByDate> = {};
export const groupeDataByDate: GroupeDataByDate = ({ filteredFiles }) => {
try {
// ! Group files by date
return filteredFiles.reduce((acc, item) => {
const computedProjects = parseProjects({ file: item });
const filesByDate = { title: item.customer, data: computedProjects };
if (acc[item.updatedAt]) {
return { ...acc, [item.updatedAt]: [...acc[item.updatedAt], filesByDate] };
}
return { ...acc, [item.updatedAt]: [filesByDate] };
}, groupeDataByDateDefaultValue);
} catch (error) {
return groupeDataByDateDefaultValue;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter