-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explorer): show project list in preround page (#3507)
* feat: implemented getTimeLeftutils and parseTimeLeft reusing the logic of getDaysLeft * feat: implemented RoundStartCountdownBadge component * feat: implemented ApplicationsCountdownBanner component * feat: extended TW theme with rainbow gradiend background * feat: hide AddToCart button in Project Details page before round start * feat: implemented RoundPage for pre/during/post round, removed unused components * test: updated tests with the changes made
- Loading branch information
Showing
8 changed files
with
288 additions
and
322 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
95 changes: 95 additions & 0 deletions
95
packages/grant-explorer/src/features/round/ApplicationsCountdownBanner.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,95 @@ | ||
import { Button } from "common/src/styles"; | ||
import { TimeLeft, getTimeLeft, parseTimeLeftString } from "../api/utils"; | ||
|
||
type ApplicationPeriodStatus = | ||
| "pre-application" | ||
| "post-application" | ||
| "during-application"; | ||
|
||
const generateCountdownString = ( | ||
targetDate: Date | undefined | ||
): string | undefined => { | ||
if (!targetDate) return undefined; | ||
|
||
const targetDateString = Math.round(targetDate.getTime() / 1000).toString(); | ||
const timeLeft: TimeLeft = getTimeLeft(targetDateString); | ||
|
||
const timeLeftString: string = parseTimeLeftString(timeLeft); | ||
|
||
return timeLeftString; | ||
}; | ||
|
||
const generateBannerString = ( | ||
status: ApplicationPeriodStatus, | ||
targetDate: Date | undefined | ||
): string => { | ||
switch (status) { | ||
case "pre-application": | ||
return `Applications open in ${generateCountdownString(targetDate)}!`; | ||
case "during-application": | ||
return `Applications close in ${generateCountdownString(targetDate)}!`; | ||
case "post-application": | ||
return `Applications are closed`; | ||
default: | ||
throw new Error("Unknown ApplicationPeriodStatus"); | ||
} | ||
}; | ||
|
||
function ApplicationsCountdownBanner(props: { | ||
startDate: Date; | ||
endDate: Date; | ||
applicationURL: string; | ||
}) { | ||
const { startDate, endDate, applicationURL } = props; | ||
|
||
let targetDate: Date | undefined = undefined; | ||
let status: ApplicationPeriodStatus = "post-application"; | ||
|
||
const currentTime = new Date(); | ||
|
||
const isBeforeApplicationPeriod = currentTime < startDate; | ||
const isDuringApplicationPeriod = | ||
currentTime >= startDate && currentTime < endDate; | ||
|
||
if (isDuringApplicationPeriod) { | ||
targetDate = endDate; | ||
status = "during-application"; | ||
} else if (isBeforeApplicationPeriod) { | ||
targetDate = startDate; | ||
status = "pre-application"; | ||
} | ||
|
||
const bannerString = generateBannerString(status, targetDate); | ||
|
||
return ( | ||
<div className="flex flex-col items-center bg-grey-50 w-fit py-6 px-36 rounded-2xl"> | ||
<p>{bannerString}</p> | ||
<ApplyButton status={status} applicationURL={applicationURL} /> | ||
</div> | ||
); | ||
} | ||
|
||
const ApplyButton = (props: { | ||
status: ApplicationPeriodStatus; | ||
applicationURL: string; | ||
testid?: string; | ||
}) => { | ||
const { status, applicationURL } = props; | ||
|
||
return ( | ||
<Button | ||
type="button" | ||
onClick={() => window.open(applicationURL, "_blank")} | ||
className="bg-orange-100 text-grey-500 mt-2 basis-full items-center justify-center shadow-sm text-sm rounded md:h-12" | ||
data-testid={ | ||
status === "during-application" | ||
? "apply-button" | ||
: "view-requirements-button" | ||
} | ||
> | ||
{status === "during-application" ? "Apply now!" : "Check requirements"} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default ApplicationsCountdownBanner; |
26 changes: 26 additions & 0 deletions
26
packages/grant-explorer/src/features/round/RoundStartCountdownBadge.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,26 @@ | ||
import { TimeLeft, getTimeLeft, parseTimeLeftString } from "../api/utils"; | ||
import { Badge } from "../common/styles"; | ||
|
||
function RoundStartCountdownBadge(props: { targetDate: Date }) { | ||
const { targetDate } = props; | ||
|
||
const targetDateString = Math.round(targetDate.getTime() / 1000).toString(); | ||
|
||
const timeLeft: TimeLeft = getTimeLeft(targetDateString); | ||
const timeLeftString: string = parseTimeLeftString(timeLeft); | ||
|
||
const badgeString = `Donations start in ${timeLeftString}`; | ||
|
||
return ( | ||
<Badge | ||
color="rainbow" | ||
rounded="full" | ||
className="flex-shrink-0 px-2.5 font-modern-era-bold" | ||
data-testid="donations-countdown-badge" | ||
> | ||
{badgeString} | ||
</Badge> | ||
); | ||
} | ||
|
||
export default RoundStartCountdownBadge; |
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
Oops, something went wrong.