Skip to content

Commit

Permalink
Removes comments and changes date function to use lib date-fns
Browse files Browse the repository at this point in the history
Co-authored-by: Diogo de Souza <[email protected]>
Co-authored-by: Alan Barbosa <[email protected]>
  • Loading branch information
3 people authored and Diogo de Souza committed Jun 3, 2024
1 parent 3e946a7 commit afe4689
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/pages/DonationsHistory/DonationsHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { IDonations, IDonationsPerDay, ViewOptions } from './types';
import { useDonations } from '@/hooks/useDonations';
import { useEffect, useState } from 'react';
import { DonationsPerDay } from './components/DonationsPerDay';
import { format } from 'date-fns';
import { ptBR } from 'date-fns/locale';

const DonationsHistory = () => {
const navigate = useNavigate();
Expand All @@ -30,19 +32,8 @@ const DonationsHistory = () => {
? ViewOptions.Received
: ViewOptions.Donated
);
}; //Toggles between donates items and received items

// Util to format date as per Figma design
const formatDate = (dateString) => {
const date = new Date(dateString);
return new Intl.DateTimeFormat('pt-BR', {
day: '2-digit',
month: 'long',
year: 'numeric',
}).format(date);
};

//Groups donations per day
const donationGroupedByDate = (donations: IDonations): IDonationsPerDay => {
return donations.reduce<IDonationsPerDay>((acc, donation) => {
const date = donation.createdAt.split('T')[0];
Expand All @@ -56,7 +47,6 @@ const DonationsHistory = () => {
}, {});
};

// Filters donations into received and given based on shelterId
const filterDonationsByCase = (
donations: IDonationsPerDay,
shelterId: string
Expand Down Expand Up @@ -93,13 +83,15 @@ const DonationsHistory = () => {
donated: donationsGivenPerDay,
received: donationsReceivedPerDay,
};
// Instantiates a DonationsPerDay container for each day

const segmentedDonationsDisplay = Object.keys(
dailyDonations[viewOption]
).map((day) => {
return (
<div key={day} className="mb-4">
<h3 className="font-semibold text-lg">{formatDate(day)}</h3>
<h3 className="font-semibold text-lg">
{format(day, "dd 'de' MMMM yyyy ", { locale: ptBR })}
</h3>
<DonationsPerDay
donations={dailyDonations[viewOption][day]}
viewOption={viewOption}
Expand Down

0 comments on commit afe4689

Please sign in to comment.