Skip to content

Commit

Permalink
fix: lock down managers Rating/Payouts feature until a project is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Aug 28, 2024
1 parent 699c443 commit 54233ba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ProjectStatus } from '@deanslist-platform/sdk'
import { useManagerFindOneProject, useManagerUpdateProjectMember } from '@deanslist-platform/web-project-data-access'
import { ManagerProjectUiPayoutsForm } from '@deanslist-platform/web-project-ui'
import { UiError, UiInfo, UiLoader, UiStack } from '@pubkey-ui/core'
import { UiError, UiInfo, UiLoader, UiStack, UiWarning } from '@pubkey-ui/core'

export function ManagerProjectDetailPayoutsTab({ projectId }: { projectId: string }) {
const { item, query, invalidate, splitByRating } = useManagerFindOneProject({ projectId })
Expand All @@ -19,7 +20,9 @@ export function ManagerProjectDetailPayoutsTab({ projectId }: { projectId: strin
message="After a session has concluded and the managers have rated all the provided feedback, they can see the total payout pool available for the given session and allocate earnings respectively based on user performance (by manually typing the amount in each user's earnings field. Alternatively, they can click on the ‘Split by Payment’ button which automatically splits the total payout pool to the participating users based on their average star score."
variant="outline"
/>

{item.status !== ProjectStatus.Closed ? (
<UiWarning variant="outline" message="You can manage payouts once the project is closed." />
) : null}
<ManagerProjectUiPayoutsForm
project={item}
splitByRating={async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ProjectStatus } from '@deanslist-platform/sdk'
import { ManagerCommentFeature } from '@deanslist-platform/web-comment-feature'
import { useManagerFindOneProject } from '@deanslist-platform/web-project-data-access'
import { UiError, UiLoader } from '@pubkey-ui/core'
import { UiError, UiLoader, UiStack, UiWarning } from '@pubkey-ui/core'

export function ManagerProjectDetailRatingsTab({ projectId }: { projectId: string }) {
const { item, query } = useManagerFindOneProject({ projectId })
Expand All @@ -12,5 +13,13 @@ export function ManagerProjectDetailRatingsTab({ projectId }: { projectId: strin
return <UiError message="Project not found." />
}

return <ManagerCommentFeature projectId={projectId} />
return (
<UiStack>
{item.status !== ProjectStatus.Closed ? (
<UiWarning variant="outline" message="You can manage ratings once the project is closed." />
) : (
<ManagerCommentFeature projectId={projectId} />
)}
</UiStack>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import { Group } from '@mantine/core'
import { useForm } from '@mantine/form'

export function ManagerProjectUiPayoutItemForm({
disabled,
update,
item,
user,
}: {
disabled?: boolean
update?: (input: ManagerUpdateProjectMemberInput) => Promise<boolean>
item: ProjectMember & { amount?: MaybeNumber; bonus?: MaybeNumber; ratingAverage?: MaybeNumber }
user: User
}) {
const ratingAverage = item.review?.ratingAverage ?? 0
const amount = item.amount ?? 0
const bonus = item.bonus ?? 0
const disabled = !update
const disabledForm = disabled || !update
const form = useForm<ManagerUpdateProjectMemberInput>({
initialValues: {
amount,
Expand Down Expand Up @@ -52,8 +54,8 @@ export function ManagerProjectUiPayoutItemForm({
/>
</Group>
<Group>
<CoreUiCurrencyInput readOnly={disabled} min={0} label="Amount" {...form.getInputProps('amount')} />
<CoreUiCurrencyInput readOnly={disabled} min={0} label="Bonus" {...form.getInputProps('bonus')} />
<CoreUiCurrencyInput readOnly={disabledForm} min={0} label="Amount" {...form.getInputProps('amount')} />
<CoreUiCurrencyInput readOnly={disabledForm} min={0} label="Bonus" {...form.getInputProps('bonus')} />
</Group>
</Group>
</form>
Expand Down
69 changes: 13 additions & 56 deletions libs/web/project/ui/src/lib/manager-project-ui-payouts-form.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ManagerUpdateProjectMemberInput, Project, ProjectMember, ProjectRole } from '@deanslist-platform/sdk'
import {
ManagerUpdateProjectMemberInput,
Project,
ProjectMember,
ProjectRole,
ProjectStatus,
} from '@deanslist-platform/sdk'
import { CoreUiButton, CoreUiDivider, CoreUiProgress } from '@deanslist-platform/web-core-ui'
import { Group, Text } from '@mantine/core'
import { UiGroup, UiStack } from '@pubkey-ui/core'
Expand All @@ -15,11 +21,9 @@ export function ManagerProjectUiPayoutsForm({
project: Project
members: ProjectMember[]
}) {
const managers = project.managers ?? []
const referral = project.referral ?? undefined
const percentageLeft = ((project.amountTotalUsdLeft ?? 0) / (project.amountTotalUsd ?? 0)) * 100

const roles: ProjectRole[] = [ProjectRole.Reviewer, ProjectRole.Manager, ProjectRole.Referral]
const disabled = project.status !== ProjectStatus.Closed
const divided = (project.amountTotalUsdLeft ?? 0) / (project.amountTotalUsd ?? 0)
const percentageLeft = divided ? divided * 100 : 0

const amountTotal = project.amountTotalUsd ?? 0
const amountManager = project.amountManagerUsd ?? 0
Expand Down Expand Up @@ -52,11 +56,11 @@ export function ManagerProjectUiPayoutsForm({
Total: {project.amountTotalUsd} USDC
</Text>
<Group gap="xs">
<Text size="sm">{project.amountTotalUsdLeft} left</Text>
<Text size="sm">{project.amountTotalUsdLeft ?? 0} left</Text>
<CoreUiProgress w={200} h={12} value={percentageLeft} tooltip={`${percentageLeft}% left`} />
</Group>
</Group>
<CoreUiButton outline onClick={() => splitByRating()}>
<CoreUiButton disabled={disabled} outline onClick={() => splitByRating()}>
Split by rating
</CoreUiButton>
</UiGroup>
Expand All @@ -76,6 +80,7 @@ export function ManagerProjectUiPayoutsForm({
<UiStack key={member.id}>
{member.user ? (
<ManagerProjectUiPayoutItemForm
disabled={disabled}
key={member.id}
update={(input) => update(member.id, input)}
item={member}
Expand All @@ -87,54 +92,6 @@ export function ManagerProjectUiPayoutsForm({
))}
</UiStack>
))}

{/*{members.map((member) => (*/}
{/* <UiStack key={member.id}>*/}
{/* <ManagerProjectUiPayoutItemForm*/}
{/* key={member.id}*/}
{/* update={(input) => update(member.id, input)}*/}
{/* item={member}*/}
{/* user={member?.user as User}*/}
{/* />*/}
{/* <CoreUiDivider />*/}
{/* </UiStack>*/}
{/*))}*/}
{/*{managers.length ? (*/}
{/* <UiStack>*/}
{/* <Text size="lg" fw={700}>*/}
{/* Managers*/}
{/* </Text>*/}
{/* {managers.map((manager) => (*/}
{/* <UiStack key={manager.id}>*/}
{/* {manager.user ? (*/}
{/* <ManagerProjectUiPayoutItemForm*/}
{/* key={manager.id}*/}
{/* item={{ amount: project.amountManagerUsd, bonus: 0 }}*/}
{/* user={manager.user}*/}
{/* />*/}
{/* ) : null}*/}
{/* <CoreUiDivider />*/}
{/* </UiStack>*/}
{/* ))}*/}
{/* </UiStack>*/}
{/*) : null}*/}
{/*{referral ? (*/}
{/* <UiStack>*/}
{/* <Text size="lg" fw={700}>*/}
{/* Referral*/}
{/* </Text>*/}
{/* {referral.user ? (*/}
{/* <ManagerProjectUiPayoutItemForm*/}
{/* item={{ amount: project.amountReferralUsd, bonus: 0 }}*/}
{/* user={referral.user}*/}
{/* />*/}
{/* ) : null}*/}
{/* </UiStack>*/}
{/*) : (*/}
{/* <Text size="lg" fw={700}>*/}
{/* No referral*/}
{/* </Text>*/}
{/*)}*/}
</UiStack>
)
}

0 comments on commit 54233ba

Please sign in to comment.