Skip to content

Commit

Permalink
Merge pull request #160 from MinaFoundation/feature/funding-round-dates
Browse files Browse the repository at this point in the history
Feature/funding round dates
  • Loading branch information
iluxonchik authored Feb 17, 2025
2 parents d82ba12 + 8412f25 commit b1868b7
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 68 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pgt-web-app",
"version": "0.1.57",
"version": "0.1.58",
"private": true,
"type": "module",
"scripts": {
Expand Down
129 changes: 118 additions & 11 deletions src/components/CreateEditFundingRound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,27 @@ type DatePhase = {
}

const DATE_PHASES: DatePhase[] = [
{ key: 'fundingRoundDates', label: 'Funding Round Period' },
{ key: 'submissionDates', label: 'Submission Phase (UTC)' },
{ key: 'considerationDates', label: 'Consideration Phase (UTC)' },
{ key: 'deliberationDates', label: 'Deliberation Phase (UTC)' },
{ key: 'votingDates', label: 'Voting Phase (UTC)' },
]

export function AddEditFundingRoundComponent({
roundId,
}: {
roundId: string | null
{ key: 'fundingRoundDates', label: "Funding Round Period (UTC)" },
{ key: 'submissionDates', label: "Submission Phase (UTC)" },
{ key: 'considerationDates', label: "Consideration Phase (UTC)" },
{ key: 'deliberationDates', label: "Deliberation Phase (UTC)" },
{ key: 'votingDates', label: "Voting Phase (UTC)" }
];

// Format dates in UTC without local timezone conversion
function formatUTC(date: Date): string {
const day = date.getUTCDate();
const month = date.getUTCMonth() + 1;
const year = date.getUTCFullYear();
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')} ${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')} UTC`;
}

export function AddEditFundingRoundComponent({
roundId
}: {
roundId: string | null
}) {
const router = useRouter()
const { toast } = useToast()
Expand Down Expand Up @@ -433,6 +443,102 @@ export function AddEditFundingRoundComponent({
</h1>
</div>

<<<<<<< HEAD
return (
<div key={phase.key} className="grid gap-4">
<Label>{phase.label}</Label>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label>From</Label>
<Popover>
<PopoverTrigger asChild>
<Button
variant="outline"
className={cn(
"w-full justify-start text-left font-normal bg-muted",
!dates.from && "text-muted-foreground"
)}
>
{dates.from ? (
formatUTC(dates.from)
) : (
<span>Pick a date</span>
)}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
selected={dates.from || undefined} // Convert null to undefined
onSelect={(date) => handleDateChange(phase.key, 'from', date || null)} // Handle undefined
disabled={loading}
initialFocus
/>
<div className="p-3 border-t">
<Input
type="time"
onChange={(e) => {
if (dates.from) {
const [hours, minutes] = e.target.value.split(':');
const newDate = new Date(dates.from);
newDate.setUTCHours(parseInt(hours), parseInt(minutes));
handleDateChange(phase.key, 'from', newDate);
}
}}
disabled={loading}
/>
</div>
</PopoverContent>
</Popover>
</div>
<div className="space-y-2">
<Label>To</Label>
<Popover>
<PopoverTrigger asChild>
<Button
variant="outline"
className={cn(
"w-full justify-start text-left font-normal bg-muted",
!dates.to && "text-muted-foreground"
)}
>
{dates.to ? (
formatUTC(dates.to)
) : (
<span>Pick a date</span>
)}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
selected={dates.to || undefined} // Convert null to undefined
onSelect={(date) => handleDateChange(phase.key, 'to', date || null)} // Handle undefined
disabled={loading}
initialFocus
/>
<div className="p-3 border-t">
<Input
type="time"
onChange={(e) => {
if (dates.to) {
const [hours, minutes] = e.target.value.split(':');
const newDate = new Date(dates.to);
newDate.setUTCHours(parseInt(hours), parseInt(minutes));
handleDateChange(phase.key, 'to', newDate);
}
}}
disabled={loading}
/>
</div>
</PopoverContent>
</Popover>
</div>
</div>
</div>
);
})}
=======
<form onSubmit={e => e.preventDefault()} className="space-y-6">
{/* Basic Information */}
<div className="space-y-4">
Expand All @@ -447,6 +553,7 @@ export function AddEditFundingRoundComponent({
disabled={loading}
/>
</div>
>>>>>>> main

<div className="space-y-4">
<Label htmlFor="description">Description</Label>
Expand Down
105 changes: 49 additions & 56 deletions src/components/phase-summary/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
type SubmissionProposalVote,
type VotingProposalVote,
} from '@/types/phase-summary'
import { formatMINA } from '@/lib/format'

type ProposalVote =
| (ProposalVoteBase & {
Expand Down Expand Up @@ -59,61 +58,55 @@ const getEmojiRank = (position: number): string => {
}

const getProposalStatus = (proposal: ProposalVote) => {
const isSubmissionPhase = 'submissionDate' in proposal
const isVotingPhase = 'isFunded' in proposal
const isDraft = proposal.status === 'DRAFT'

if (isVotingPhase) {
return (proposal as VotingProposalVote).isFunded
? {
label: 'Funded',
bgColor: 'bg-emerald-50/50 hover:bg-emerald-50/80',
borderColor: 'border-emerald-200/50',
textColor: 'text-emerald-600',
}
: {
label: 'Not Funded',
bgColor: 'bg-rose-50/50 hover:bg-rose-50/80',
borderColor: 'border-rose-200/50',
textColor: 'text-rose-600',
}
}

if (isSubmissionPhase) {
return {
label: 'Submitted',
bgColor: 'bg-blue-50/50 hover:bg-blue-50/80',
borderColor: 'border-blue-200/50',
textColor: 'text-blue-600',
}
}

if (isDraft) {
return {
label: 'Draft',
bgColor: 'bg-gray-50/50 hover:bg-gray-50/80',
borderColor: 'border-gray-200/50',
textColor: 'text-gray-600',
}
}

const hasMovedForward = ['DELIBERATION', 'VOTING', 'APPROVED'].includes(
proposal.status,
)
return hasMovedForward
? {
label: 'Moving Forward',
bgColor: 'bg-emerald-50/50 hover:bg-emerald-50/80',
borderColor: 'border-emerald-200/50',
textColor: 'text-emerald-600',
}
: {
label: 'Not Moving Forward',
bgColor: 'bg-rose-50/50 hover:bg-rose-50/80',
borderColor: 'border-rose-200/50',
textColor: 'text-rose-600',
}
}
const isSubmissionPhase = 'submissionDate' in proposal;
const isVotingPhase = 'isFunded' in proposal;
const isDraft = proposal.status === 'DRAFT';

if (isVotingPhase) {
return (proposal as VotingProposalVote).isFunded ? {
label: 'Funded',
bgColor: 'bg-emerald-50/50 hover:bg-emerald-50/80',
borderColor: 'border-emerald-200/50',
textColor: 'text-emerald-600'
} : {
label: 'Not Funded',
bgColor: 'bg-rose-50/50 hover:bg-rose-50/80',
borderColor: 'border-rose-200/50',
textColor: 'text-rose-600'
};
}

if (isSubmissionPhase) {
return {
label: 'Submitted',
bgColor: 'bg-blue-50/50 hover:bg-blue-50/80',
borderColor: 'border-blue-200/50',
textColor: 'text-blue-600'
};
}

if (isDraft) {
return {
label: 'Draft',
bgColor: 'bg-gray-50/50 hover:bg-gray-50/80',
borderColor: 'border-gray-200/50',
textColor: 'text-gray-600'
};
}

const hasMovedForward = ['DELIBERATION', 'VOTING', 'APPROVED'].includes(proposal.status);
return hasMovedForward ? {
label: 'Approved',
bgColor: 'bg-emerald-50/50 hover:bg-emerald-50/80',
borderColor: 'border-emerald-200/50',
textColor: 'text-emerald-600'
} : {
label: 'Rejected',
bgColor: 'bg-rose-50/50 hover:bg-rose-50/80',
borderColor: 'border-rose-200/50',
textColor: 'text-rose-600'
};
};

export const ProposalCard: FC<Props> = ({
proposal,
Expand Down

0 comments on commit b1868b7

Please sign in to comment.