-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Create UserFunds component to extract this logic from myfun…
…ds page component
- Loading branch information
Showing
2 changed files
with
73 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
frontend/gostarkme-web/components/modules/myfunds/UserFunds.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use client"; | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import FundCard from '@/components/modules/myfunds/FundCard'; | ||
|
||
interface UserFundsProps { | ||
userAddress: string; | ||
} | ||
|
||
const UserFunds: React.FC<UserFundsProps> = ({ userAddress }) => { | ||
const [funds, setFunds] = useState<object[]>([]); | ||
|
||
useEffect(() => { | ||
// TODO: Implement funds fetching using 'userAddress' | ||
setFunds([ | ||
{ | ||
id: 1, | ||
type: "Project", | ||
title: "Batman's fund", | ||
description: "Example of card without delete button", | ||
}, | ||
{ | ||
id: 2, | ||
type: "Project", | ||
title: "Deadpool's fund", | ||
description: "I need help with my project to develop an awesome project like Go Stark Me", | ||
onClick: handleDeleteFund | ||
}, | ||
{ | ||
id: 3, | ||
type: "Fund", | ||
title: "Spider-Man's fund", | ||
description: "Text to prove that we add elipsis when text exceds card width and we don't break the layout. asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf", | ||
onClick: handleDeleteFund | ||
} | ||
]); | ||
}, []); | ||
|
||
const handleDeleteFund = (fundId: number) => { | ||
// TODO: Implement fund deletion based on a unique id or receive the fund object and delete it | ||
alert(`Deleting fund with id: ${fundId}`); | ||
} | ||
|
||
return ( | ||
<div> | ||
{funds.length === 0 ? ( | ||
<div className="flex justify-center items-center h-64"> | ||
<div className="text-center text-gray-500"> | ||
No funds found for address {userAddress.slice(0, 5)}...{userAddress.slice(-4)} | ||
</div> | ||
</div> | ||
) : ( | ||
<div className="grid grid-cols-1 md:grid-cols-2 gap-y-10 gap-x-16"> | ||
{funds.map((fund: any, index: number) => ( | ||
<FundCard | ||
key={index} | ||
type={fund.type} | ||
title={fund.title} | ||
description={fund.description} | ||
{... fund.onClick && { onClick: () => fund.onClick(fund.id) }} | ||
/> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default UserFunds; |