Skip to content

Commit

Permalink
[RAB-4] Separate transactions into TransactionHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Miklaszewski committed Apr 26, 2023
1 parent 62774e3 commit 2c0481d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 56 deletions.
1 change: 0 additions & 1 deletion apps/next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@types/react": "18.0.37",
"@types/react-dom": "18.0.11",
"autoprefixer": "10.4.14",
"axios": "^1.3.6",
"date-fns": "^2.29.3",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
Expand Down
30 changes: 2 additions & 28 deletions apps/next-app/src/pages/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { AvatarChanger } from 'shared/components/profile/AvatarChanger';
import { EditProfileForm } from 'shared/components/profile/EditProfileForm';
import { getApolloServerClient } from 'shared/services/apollo';
import { EDGE_FUNCTION_NAMES } from 'constants/EDGE_FUNCTION_NAMES';
import { Checkmark } from 'shared/components/Checkmark';
import { Crossmark } from 'shared/components/Crossmark';
import { getSubscriptionPrice } from 'utils/getSubscriptionPrice';
import { format, fromUnixTime } from 'date-fns';
import { TransactionHistory } from 'shared/components/subscriptions/TransactionHistory';

interface ProfileProps {
profile: GetProfileQuery['profilesCollection'];
Expand All @@ -25,30 +22,7 @@ const Profile = ({ profile, charges }: ProfileProps) => {

<AvatarChanger profileAvatarSrc={userProfile?.node.avatar_url} />
<EditProfileForm fullName={userProfile?.node.full_name!} />
<div className="max-w-xl w-full">
<h2 className="mt-8 text-2xl">Transaction history</h2>
<div className="flex flex-col">
{charges.charges.data.map(
({ id, created, description, amount, currency, status }: any) => (
<div
key={id}
className="flex justify-between w-full border-b-2 border-slate-800 py-6"
>
<div>
{description}{' '}
<span className="text-slate-400">
({format(fromUnixTime(created), 'Pp')})
</span>
</div>
<div>
{getSubscriptionPrice(amount)} {currency.toUpperCase()}
</div>
{status === 'succeeded' ? <Checkmark /> : <Crossmark isError />}
</div>
)
)}
</div>
</div>
<TransactionHistory transactions={charges} />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { TransactionHistory } from './transactionHistory.component';
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { format, fromUnixTime } from 'date-fns';
import { Checkmark } from 'shared/components/Checkmark';
import { Crossmark } from 'shared/components/Crossmark';
import { getSubscriptionPrice } from 'utils/getSubscriptionPrice';

interface TransactionHistoryProps {
transactions: any;
}

export const TransactionHistory = ({
transactions,
}: TransactionHistoryProps) => {
return (
<div className="max-w-xl w-full">
<h2 className="mt-8 text-2xl">Transaction history</h2>
<div className="flex flex-col">
{transactions.charges.data.map(
({ id, created, description, amount, currency, status }: any) => (
<div
key={id}
className="flex justify-between w-full border-b-2 border-slate-800 py-6"
>
<div>
{description}{' '}
<span className="text-slate-400">
({format(fromUnixTime(created), 'Pp')})
</span>
</div>
<div>
{getSubscriptionPrice(amount)} {currency.toUpperCase()}
</div>
{status === 'succeeded' ? <Checkmark /> : <Crossmark isError />}
</div>
)
)}
</div>
</div>
);
};
33 changes: 6 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2c0481d

Please sign in to comment.