diff --git a/src/components/Project/ExpandableMilestone.tsx b/src/components/Project/ExpandableMilestone.tsx index c586fab3..5ad2be59 100644 --- a/src/components/Project/ExpandableMilestone.tsx +++ b/src/components/Project/ExpandableMilestone.tsx @@ -34,11 +34,12 @@ type ExpandableDropDownsProps = { isProjectOwner: boolean; balance: number; project: Project; + milestonLoadingTitle: string; }; const ExpandableDropDowns = (props: ExpandableDropDownsProps) => { - const { setLoading, project, setSuccess, setSuccessTitle, setError, milestone, index, modified, setOpenVotingList, approversPreview, firstPendingMilestone, projectInMilestoneVoting, isApplicant, canVote, user, projectType, isProjectOwner, balance } = props + const { setLoading, project, setSuccess, setSuccessTitle, setError, milestone, index, modified, setOpenVotingList, approversPreview, firstPendingMilestone, projectInMilestoneVoting, isApplicant, canVote, user, projectType, isProjectOwner, balance, milestonLoadingTitle } = props const [expanded, setExpanded] = useState(false); const [showPolkadotAccounts, setShowPolkadotAccounts] = @@ -148,20 +149,24 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => { await updateFirstPendingMilestone(Number(project.id), (Number(project.first_pending_milestone) + 1)) setSuccess(true); setSuccessTitle('Your vote was successful. This milestone has been completed.'); + setLoading(false); break; } else if (result.status) { setSuccess(true); setSuccessTitle('Your vote was successful.'); + setLoading(false); break; } else if (result.txError) { setError({ message: result.errorMessage }); + setLoading(false); break; } else if (pollResult != ImbueChainPollResult.Pending) { setSuccess(true); setSuccessTitle('Request resolved successfully'); + setLoading(false); break; } await new Promise((f) => setTimeout(f, 1000)); @@ -170,9 +175,13 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => { setError({ message: 'Could not vote. Please try again later' }); // eslint-disable-next-line no-console console.error(error) - } finally { setLoading(false); } + // finally { + // console.log("in finally"); + + // setLoading(false); + // } }; @@ -294,32 +303,37 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => {
- {milestone?.is_approved ? ( - - ) : milestone?.milestone_index == firstPendingMilestone && - projectInMilestoneVoting ? ( - - ) : ( - - )} + { + milestonLoadingTitle + ?

{milestonLoadingTitle}

+ : (<>{milestone?.is_approved ? ( + + ) : milestone?.milestone_index == firstPendingMilestone && + projectInMilestoneVoting ? ( + + ) : ( + + )}) + } + { {milestone?.description}

- {!isApplicant && + {!milestonLoadingTitle && !isApplicant && milestone.milestone_index == firstPendingMilestone && projectInMilestoneVoting && ( { )} - {(isApplicant || (projectType === 'grant' && isProjectOwner)) && + {!milestonLoadingTitle && (isApplicant || (projectType === 'grant' && isProjectOwner)) && milestone.milestone_index == firstPendingMilestone && !projectInMilestoneVoting && !milestone?.is_approved && ( @@ -395,7 +409,7 @@ const ExpandableDropDowns = (props: ExpandableDropDownsProps) => { )} - {isApplicant && milestone.is_approved && ( + {!milestonLoadingTitle && isApplicant && milestone.is_approved && (
- {firstPendingMilestone !== undefined && - milestone?.milestone_index <= firstPendingMilestone && - projectInMilestoneVoting ? ( - <> - {milestone.is_approved ? ( -

- Completed -

- ) : ( -

setOpenVotingList(true)} - className='text-lg cursor-pointer' - > - Votes -

- )} - - ) : ( - <> - {milestone.is_approved ? ( -

- Completed -

- ) : ( -

- Pending -

- )} - - )} + { + milestoneLoding + ?

Loading...

+ : ( + <> + {firstPendingMilestone !== undefined && + milestone?.milestone_index <= firstPendingMilestone && + projectInMilestoneVoting + ? ( + <> + {milestone.is_approved + ? ( +

+ Completed +

) + : ( +

setOpenVotingList(true)} + className='text-lg cursor-pointer' + > + Votes +

+ )} + ) + : ( + <> + {milestone.is_approved + ? ( +

+ Completed +

) + : ( +

+ Pending +

+ )} + + )} + ) + } +
); diff --git a/src/components/Project/VotingList/VotingList.tsx b/src/components/Project/VotingList/VotingList.tsx index 319daab3..35dcb046 100644 --- a/src/components/Project/VotingList/VotingList.tsx +++ b/src/components/Project/VotingList/VotingList.tsx @@ -19,6 +19,7 @@ type VotingListProps = { open: boolean; firstPendingMilestone: number | undefined; setOpenVotingList: (_value: boolean) => void; + setMilestoneVotes: (_value: any) => void; approvers: User[]; chainProjectId: number | undefined; } @@ -29,7 +30,7 @@ type MilestoneVotes = { } const VotingList = (props: VotingListProps) => { - const { firstPendingMilestone, setOpenVotingList, approvers, chainProjectId, open } = props + const { firstPendingMilestone, setOpenVotingList, approvers, chainProjectId, open, setMilestoneVotes } = props const [value, setValue] = React.useState(0); const [list, setList] = useState([]); const [votes, setVotes] = useState([]) @@ -50,6 +51,7 @@ const VotingList = (props: VotingListProps) => { chainProjectId, firstPendingMilestone ); + setMilestoneVotes(milestoneVotes) const votesArray = Object.keys(milestoneVotes) @@ -62,14 +64,15 @@ const VotingList = (props: VotingListProps) => { setVotes(votes) } } catch (error) { - console.log(error); + // eslint-disable-next-line no-console + console.error(error); } finally { setLoading(false) } } setVotingList() - }, [chainProjectId, user, firstPendingMilestone]) + }, [chainProjectId, user, firstPendingMilestone, setMilestoneVotes]) useEffect(() => { const votedYes: User[] = [] diff --git a/src/pages/api/project/[...id].ts b/src/pages/api/project/[...id].ts index 47eedf94..e08d2dc4 100644 --- a/src/pages/api/project/[...id].ts +++ b/src/pages/api/project/[...id].ts @@ -125,13 +125,15 @@ export default nextConnect() status_id, completed: status_id === OffchainProjectState.Completed, project_in_voting_of_no_confidence, + first_pending_milestone, + project_in_milestone_voting }; - if (first_pending_milestone) - newProject.first_pending_milestone = first_pending_milestone; + // if (first_pending_milestone) + // newProject.first_pending_milestone = first_pending_milestone; - if (project_in_milestone_voting) - newProject.project_in_milestone_voting = project_in_milestone_voting; + // if (project_in_milestone_voting) + // newProject.project_in_milestone_voting = project_in_milestone_voting; const project = await models.updateProject(projectId, newProject)(tx); diff --git a/src/pages/projects/[id].tsx b/src/pages/projects/[id].tsx index 03e5a095..192f1ad2 100644 --- a/src/pages/projects/[id].tsx +++ b/src/pages/projects/[id].tsx @@ -95,7 +95,8 @@ function Project() { const [projectOwner, setProjectOwner] = useState(); const [showRefundButton, setShowRefundButton] = useState(false); // TODO: Create votes table - const [milestoneVotes] = useState({}); + const [milestoneVotes, setMilestoneVotes] = useState({}); + const [milestonLoadingTitle, setMilestoneLoadingTitle] = useState("") const [projectInMilestoneVoting, setProjectInMilestoneVoting] = useState(); @@ -141,7 +142,7 @@ function Project() { // fetching the project data from api and from chain useEffect(() => { if (projectId && !userLoading) { - console.log("useeffect hit"); + console.log("🚀 ~ file: [id].tsx:144 ~ useEffect ~ projectId:", projectId) getProject(); } }, [projectId, userLoading]); @@ -198,17 +199,17 @@ function Project() { break; case OffchainProjectState.Accepted: if (!project.chain_project_id) { - setWait(true); setWaitMessage( `Waiting for ${freelancer.display_name} to start the work` ); + setWait(true); } if (!project.chain_project_id && project.brief_id) { - setWait(true); setWaitMessage( `Your project is being created on the chain. This may take up to 6 seconds` ); + setWait(true); } break; } @@ -307,6 +308,7 @@ function Project() { }; const syncProject = async (project: Project) => { + setMilestoneLoadingTitle("Loading Votes ...") try { const imbueApi = await initImbueAPIInfo(); const chainService = new ChainService(imbueApi, user); @@ -324,21 +326,22 @@ function Project() { ) return - setWait(true) - setWaitMessage("Syncing project with chain") + // setWaitMessage("Syncing project with chain") + // setWait(true) + // setMilestoneLoadingTitle("Getting milestone data from chain...") const newProject = { ...project, project_in_milestone_voting: onChainProjectRes.projectInMilestoneVoting, first_pending_milestone: firstPendingMilestoneChain, project_in_voting_of_no_confidence: onChainProjectRes.projectInVotingOfNoConfidence, - milestones: onChainProjectRes.milestones + // milestones: onChainProjectRes.milestones } project.project_in_milestone_voting = onChainProjectRes.projectInMilestoneVoting project.first_pending_milestone = firstPendingMilestoneChain project.project_in_voting_of_no_confidence = onChainProjectRes.projectInVotingOfNoConfidence - project.milestones = onChainProjectRes.milestones + // project.milestones = onChainProjectRes.milestones await updateProject(project.id, newProject); setWait(false) @@ -359,6 +362,7 @@ function Project() { console.error(error) setError({ message: "Could sync project. ", error }) } finally { + setMilestoneLoadingTitle("") setLoading(false) } } @@ -850,6 +854,7 @@ function Project() { index={index} milestone={milestone} modified={milestone?.modified as Date} + milestonLoadingTitle={milestonLoadingTitle} /> ); } @@ -865,6 +870,7 @@ function Project() { setOpenVotingList={setOpenVotingList} numberOfMileSotnes={project.milestones} isChainLoading={chainLoading} + milestoneLoding={milestonLoadingTitle ? true : false} /> @@ -937,6 +943,7 @@ function Project() { setOpenVotingList={setOpenVotingList} approvers={approversPreview} chainProjectId={project.chain_project_id} + setMilestoneVotes={setMilestoneVotes} />