Skip to content

Commit

Permalink
added contribution status and fixed participation score contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtmeeseeks committed Dec 9, 2024
1 parent 0800a35 commit a6429b3
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 41 deletions.
16 changes: 11 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@aut-labs/abi-types": "^0.0.88-dev",
"@aut-labs/connector": "^0.0.205",
"@aut-labs/d-aut": "^1.0.206-dev",
"@aut-labs/sdk": "^0.0.230-dev",
"@aut-labs/sdk": "^0.0.231-dev",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@marker.io/browser": "^0.19.0",
Expand Down
93 changes: 78 additions & 15 deletions src/pages/AutID/AutHub/AutHubContributionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Box from "@mui/material/Box";
import ArrowIcon from "@assets/autos/move-right.svg?react";

import {
Alert,
Paper,
Stack,
SvgIcon,
Expand All @@ -23,12 +24,14 @@ import useQueryContributions from "@utils/hooks/GetContributions";
import { useCommitAnyContributionMutation } from "@api/contributions.api";
import { useWalletConnector } from "@aut-labs/connector";
import useQueryContributionCommits, {
ContributionCommit
ContributionCommit,
ContributionStatus,
ContributionStatusMap
} from "@utils/hooks/useQueryContributionCommits";
import { TaskContributionNFT } from "@aut-labs/sdk";
import { Link } from "react-router-dom";
import { GithubCommitContribution } from "@api/models/contribution-types/github-commit.model";
import useQueryHubPeriod from "@utils/hooks/useQueryHubPeriod";
import OverflowTooltip from "@components/OverflowTooltip";

const StyledTableCell = styled(TableCell)(({ theme }) => ({
[`&.${tableCellClasses.head}, &.${tableCellClasses.body}`]: {
Expand Down Expand Up @@ -72,6 +75,25 @@ const TableListItem = memo(({ contribution, commit }: TableListItemProps) => {
).toString();
}, [contribution?.properties?.endDate]);

const status = useMemo(() => {
if (!commit?.status) {
return {
state: "Open",
severity: "info"
};
}
let severity = "warning";
if (commit?.status === ContributionStatus.Rejected) {
severity = "error";
} else if (commit?.status === ContributionStatus.Complete) {
severity = "success";
}
return {
state: ContributionStatusMap[commit?.status],
severity
};
}, [commit?.status]);

return (
<StyledTableRow
sx={{
Expand Down Expand Up @@ -101,12 +123,24 @@ const TableListItem = memo(({ contribution, commit }: TableListItemProps) => {
>
<StyledTableCell align="left">
<Stack>
<Typography variant="subtitle2" fontWeight="normal" color="white">
{contribution?.name}
</Typography>
<Typography variant="caption" fontWeight="normal" color="white">
{contribution?.description}
</Typography>
<OverflowTooltip
typography={{
variant: "subtitle2",
fontWeight: "400",
letterSpacing: "0.66px"
}}
maxLine={1}
text={contribution?.name}
/>
<OverflowTooltip
typography={{
variant: "caption",
fontWeight: "400",
letterSpacing: "0.66px"
}}
maxLine={2}
text={contribution?.description}
/>
</Stack>
</StyledTableCell>
<StyledTableCell align="left">
Expand Down Expand Up @@ -150,6 +184,32 @@ const TableListItem = memo(({ contribution, commit }: TableListItemProps) => {
</Typography>
</StyledTableCell>

<StyledTableCell align="left">
<Alert
variant="filled"
sx={{
borderRadius: "8px",
border: 0,
height: "40px",
width: "134px",
display: "flex",
color: "white",
fontFamily: "FractulRegular",
fontWeight: "bold",
alignItems: "center",
".MuiAlert-message": {
overflow: "hidden"
},
".MuiAlert-icon": {
marginRight: theme.spacing(1)
}
}}
severity={status?.severity as any}
>
{status?.state}
</Alert>
</StyledTableCell>

<StyledTableCell align="left">
<Box
sx={{
Expand Down Expand Up @@ -177,15 +237,9 @@ const TableListItem = memo(({ contribution, commit }: TableListItemProps) => {
) : (
<AutOsButton
type="button"
color="success"
color="primary"
variant="contained"
sx={{
"&.MuiButton-root": {
backgroundColor: "#12B76A"
},
"&.Mui-disabled": {
color: `${theme.palette.offWhite.light} !important`
},
width: "100px"
}}
to={`contribution/${contribution?.properties?.id}`}
Expand Down Expand Up @@ -333,6 +387,15 @@ export const AutHubTasksTable = ({ header }) => {
End Date
</Typography>
</StyledTableCell>
<StyledTableCell align="center">
<Typography
variant="body"
fontWeight="normal"
color="offWhite.dark"
>
Status
</Typography>
</StyledTableCell>
<StyledTableCell align="center">
<Typography
variant="body"
Expand Down
25 changes: 11 additions & 14 deletions src/pages/AutID/AutHub/AutHubEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ const AutHubEdit = () => {

const { data: periodData } = useQueryHubPeriod();

const { pointsGiven, expectedPoints, endDate } = periodData || {};
const initialScore = 100;

useEffect(() => {
dispatch(updateAutState({ selectedHubAddress: params.hubAddress }));
console.log(
Expand Down Expand Up @@ -617,7 +614,7 @@ const AutHubEdit = () => {
>
Current Period Contribution
</Typography>
{pointsGiven < expectedPoints ? (
{periodData?.pointsGiven < periodData?.expectedPoints ? (
<SvgIcon
sx={{
fill: "transparent",
Expand Down Expand Up @@ -649,7 +646,7 @@ const AutHubEdit = () => {
period ends in
</Typography>
<Countdown
date={endDate}
date={periodData?.endDate}
renderer={AutCountdown}
/>
</Box>
Expand Down Expand Up @@ -686,7 +683,7 @@ const AutHubEdit = () => {
lineHeight="48px"
color="offWhite.main"
>
{pointsGiven}
{periodData?.pointsGiven}
</Typography>
<Typography
lineHeight="48px"
Expand All @@ -710,11 +707,11 @@ const AutHubEdit = () => {
}}
color="offWhite.dark"
>
{expectedPoints}
{periodData?.expectedPoints}
</Typography>
</Box>

{pointsGiven < expectedPoints && (
{periodData?.pointsGiven < periodData?.expectedPoints && (
<Box
sx={{
width: "100%",
Expand Down Expand Up @@ -746,7 +743,7 @@ const AutHubEdit = () => {
}}
variant="determinate"
value={
(pointsGiven / (expectedPoints || 1)) * 100
(periodData?.pointsGiven / (periodData?.expectedPoints || 1)) * 100
}
/>
</Box>
Expand All @@ -761,8 +758,8 @@ const AutHubEdit = () => {
</Typography>
</Box>
)}
{pointsGiven ===
expectedPoints && (
{periodData?.pointsGiven ===
periodData?.expectedPoints && (
<Box
sx={{
width: "100%",
Expand Down Expand Up @@ -811,7 +808,7 @@ const AutHubEdit = () => {
</Typography>
</Box>
)}
{pointsGiven > expectedPoints && (
{periodData?.pointsGiven > periodData?.expectedPoints && (
<Box
sx={{
width: "100%",
Expand Down Expand Up @@ -953,7 +950,7 @@ const AutHubEdit = () => {
color="offWhite.main"
fontWeight="normal"
>
{initialScore}
{periodData?.score}
</Typography>
<SubtitleWithInfo
title="score"
Expand All @@ -966,7 +963,7 @@ const AutHubEdit = () => {
color="offWhite.main"
fontWeight="normal"
>
{pointsGiven}
{periodData?.pointsGiven}
</Typography>
<SubtitleWithInfo
title="points"
Expand Down
3 changes: 1 addition & 2 deletions src/pages/AutID/AutHub/AutHubList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const { IconContainer } = EditContentElements;

const HubListItem = memo(({ row }: { row: AutOSHub }) => {
const { data: periodData } = useQueryHubPeriod();
const initialScore = 100;
const theme = useTheme();
const { address } = useAccount();
const autID = useSelector(SelectedAutID);
Expand Down Expand Up @@ -301,7 +300,7 @@ const HubListItem = memo(({ row }: { row: AutOSHub }) => {
color="offWhite.main"
fontWeight="normal"
>
{initialScore}
{periodData?.score}
</Typography>
<SubtitleWithInfo
title="score"
Expand Down
1 change: 0 additions & 1 deletion src/pages/Tasks/Contributions/Contributions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const Contributions = () => {
const contributionTemplate = useMemo(() => {
const contribution = data?.[0];
if (!contribution) return null;
debugger;
if (contribution instanceof OpenTaskContribution) {
return <OpenTask contribution={contribution} commit={commit} />;
} else if (contribution instanceof QuizTaskContribution) {
Expand Down
14 changes: 14 additions & 0 deletions src/utils/hooks/useQueryContributionCommits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@ import { environment } from "@api/environment";
import axios from "axios";
import { useWalletConnector } from "@aut-labs/connector";

export enum ContributionStatus {
Pending = 1,
Rejected = 2,
Complete = 3
}

export const ContributionStatusMap = {
[ContributionStatus.Pending]: "Pending",
[ContributionStatus.Rejected]: "Rejected",
[ContributionStatus.Complete]: "Complete"
};

export interface ContributionCommit {
id: string;
hub: Hub;
data: any;
status: ContributionStatus;
who: string;
contribution: Partial<TaskContributionProperties>;
dataDecrypted?: boolean;
Expand All @@ -35,6 +48,7 @@ const GET_CONTRIBUTION_COMMITS = gql`
id
hub
data
status
who
contribution {
id
Expand Down
6 changes: 3 additions & 3 deletions src/utils/hooks/useQueryHubPeriod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const fetchHubPeriodData = async (
taskManager.functions.currentPeriodStart(),
taskManager.functions.currentPeriodEnd(),
taskManager.functions.getMemberPointsGiven(who, Number(periodId)),
participationScore.functions.memberParticipations(who, Number(periodId)), // {score: number; performance: number}
participationScore.functions.calcExpectedPoints(
participationScore.functions.memberActivities(who, Number(periodId)), // {participationScore: number; performance: number}
participationScore.functions.calcExpectedContributionPoints(
+selectedHub.commitment,
Number(periodId)
)
Expand All @@ -50,7 +50,7 @@ const fetchHubPeriodData = async (
startDate: new Date(Number(startDate) * 1000),
endDate: new Date(Number(endDate) * 1000),
pointsGiven: Number(pointsGiven),
score: Number(participation.score),
score: Number(participation.participationScore) || 100,
performance: Number(participation.performance),
expectedPoints: Number(expectedPoints)
};
Expand Down

0 comments on commit a6429b3

Please sign in to comment.