-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement random project donation
& Update API client
- Loading branch information
1 parent
8892ee8
commit 855c415
Showing
8 changed files
with
209 additions
and
56 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
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
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
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
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,37 @@ | ||
import { potlock } from "@/common/api/potlock"; | ||
import { POTLOCK_REGISTRY_LIST_ID } from "@/common/constants"; | ||
import { Button, Skeleton } from "@/common/ui/components"; | ||
|
||
import { useDonation } from "../hooks/feature"; | ||
|
||
export const DonationRandomButton = () => { | ||
const { | ||
isLoading: isRandomPGRegistryEntryLoading, | ||
data: isRandomPGRegistryEntry, | ||
mutate: refetchRandomPGRegistryEntry, | ||
} = potlock.useRandomListRegistration({ | ||
listId: POTLOCK_REGISTRY_LIST_ID, | ||
status: "Approved", | ||
}); | ||
|
||
const randomProjectAccountId = isRandomPGRegistryEntry?.registrant.id; | ||
|
||
const { openDonationModal: openRandomDonationModal } = useDonation({ | ||
accountId: randomProjectAccountId ?? "unknown", | ||
}); | ||
|
||
const onDonateRandomlyClick = (event: React.MouseEvent) => { | ||
openRandomDonationModal(event); | ||
refetchRandomPGRegistryEntry(); | ||
}; | ||
|
||
return isRandomPGRegistryEntryLoading ? ( | ||
<Skeleton className="h-10 w-full bg-[rgba(246,118,122,0.3)] md:w-[180px]" /> | ||
) : ( | ||
randomProjectAccountId && ( | ||
<Button className="w-full md:w-[180px]" onClick={onDonateRandomlyClick}> | ||
Donate Randomly | ||
</Button> | ||
) | ||
); | ||
}; |
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,25 @@ | ||
import { useCallback } from "react"; | ||
|
||
import { useModal } from "@ebay/nice-modal-react"; | ||
|
||
import { dispatch } from "@/app/_store"; | ||
|
||
import { DonationModal } from "../components/DonationModal"; | ||
import { DonationParameters } from "../models"; | ||
|
||
export const useDonation = (props: DonationParameters) => { | ||
const modal = useModal(DonationModal); | ||
|
||
return { | ||
openDonationModal: useCallback( | ||
(event: React.MouseEvent) => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
dispatch.donation.reset(); | ||
modal.show(props); | ||
}, | ||
|
||
[modal, props], | ||
), | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,27 +1,3 @@ | ||
import { useCallback } from "react"; | ||
|
||
import { useModal } from "@ebay/nice-modal-react"; | ||
|
||
import { dispatch } from "@/app/_store"; | ||
|
||
import { DonationModal } from "./components/DonationModal"; | ||
import { DonationParameters } from "./models"; | ||
|
||
export { DonationRandomButton } from "./components/buttons"; | ||
export { donationModel } from "./models"; | ||
|
||
export const useDonation = (props: DonationParameters) => { | ||
const modal = useModal(DonationModal); | ||
|
||
return { | ||
openDonationModal: useCallback( | ||
(event: React.MouseEvent) => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
dispatch.donation.reset(); | ||
modal.show(props); | ||
}, | ||
|
||
[modal, props], | ||
), | ||
}; | ||
}; | ||
export * from "./hooks/feature"; |
Oops, something went wrong.