Skip to content

Commit

Permalink
Latest bug fixes (#251)
Browse files Browse the repository at this point in the history
* freelancer search page fixed

* added complete milestone api

* latest fixes

* voting reset fix

* dummy push

* updating voting state when treshold reached or all votes are done

* attachment refactorization

* latest bug fixes

* application title length break

* build fix

* switch profile fix
  • Loading branch information
ssani7 authored Nov 6, 2023
1 parent 1a704e7 commit 22bbb0f
Show file tree
Hide file tree
Showing 25 changed files with 1,082 additions and 759 deletions.
2 changes: 1 addition & 1 deletion src/components/BriefComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function BriefComponent({ brief }: { brief: Brief }) {
<div className='flex border-b hover:bg-imbue-light-purple-three cursor-pointer last:border-b-0'>
<div
onClick={() => router.push(`/briefs/${brief.id}`)}
className='py-9 px-7 max-w-[70%] w-full'
className='py-9 px-7 max-w-[70%] w-full break-words'
>
<p className='text-2xl text-imbue-purple-dark'>{brief.headline}</p>
<div className='flex text-sm text-imbue-dark-coral gap-5 mt-5'>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Briefs/BriefInsights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const BriefInsights = ({ brief }: BriefInsightsProps) => {

return (
<div className='flex mt-[1.5rem] flex-col lg:flex-row gap-4 lg:gap-2 bg-white rounded-bl-[20px] rounded-br-[20px] border-t border-t-[rgba(3, 17, 106, 0.12)] p-7 lg:px-[50px] lg:py-[2rem]'>
<div className='flex flex-col gap-[20px] flex-grow flex-shrink-0 basis-[75%] mr-[5%] relative'>
<div className='flex flex-col gap-[20px] flex-grow flex-shrink-0 basis-[75%] mr-[5%] relative break-all'>
<div className='brief-title'>
<h3 className='text-[1.25rem] text-imbue-purple-dark leading-[1.5] font-normal m-0 p-0'>
<h3 className='text-[1.25rem] text-imbue-purple-dark leading-[1.5] font-normal m-0 p-0 max-w-[89%]'>
{brief?.headline}
</h3>
<span
Expand Down
10 changes: 6 additions & 4 deletions src/components/PopupScreens/SwitchToFreelancer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@ const SwitchToFreelancer = () => {
const [isFreelancer, setIsFreelancer] = useState<boolean>(false)

useEffect(() => {
setloading(true)

const checkFreelancerProfile = async () => {
if (!user?.username) return;

setloading(true)
try {
const freelancer = await getFreelancerProfile(user?.username);
if (!freelancer?.id) setIsFreelancer(false);
if (freelancer?.id) setIsFreelancer(true);
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
} finally {
setloading(false);
}
}
checkFreelancerProfile()
}, [loadingUser, router, user?.username]);
!loadingUser && checkFreelancerProfile()
}, [loadingUser, user?.username]);

if (loadingUser || loading) return <FullScreenLoader />

Expand Down
6 changes: 3 additions & 3 deletions src/components/Project/ProjectApprovers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const ProjectApprovers = (props: ProjectApproversType) => {
{approversPreview?.slice(0, 4).map((approver: any, index: number) => (
<div
key={index}
className={`col-span-3 flex text-content px-3 py-2 rounded-xl gap-4 items-center ${approver?.display_name && 'cursor-pointer'} ${approver.id === user?.id && "bg-[#FFDAD8]"}`}
className={`col-span-3 flex text-content px-2 py-2 rounded-xl gap-2 items-center ${approver?.display_name && 'cursor-pointer'} ${approver.id === user?.id && "bg-[#FFDAD8]"}`}
onClick={() =>
approver.display_name &&
router.push(`/profile/${approver.username}`)
Expand All @@ -164,8 +164,8 @@ const ProjectApprovers = (props: ProjectApproversType) => {
<div className='flex flex-col'>
<span className='text-base'>
{
approver?.display_name.length > 12
? approver.display_name.substring(0, 12) + "..."
approver?.display_name.length > 5
? approver.display_name.substring(0, 5) + "..."
: approver.display_name
}
</span>
Expand Down
5 changes: 3 additions & 2 deletions src/components/Project/ProjectBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type ProjectBalanceType = {
user: User;
handlePopUpForUser: () => void;
setBalance: (_balance: number) => void;
setBalanceLoading: (_loading: boolean) => void;
balanceLoading: boolean;
}

const Currencies = [
Expand Down Expand Up @@ -40,8 +42,7 @@ const Currencies = [
]

const ProjectBalance = (props: ProjectBalanceType) => {
const { balance, project, user, handlePopUpForUser, setBalance } = props;
const [balanceLoading, setBalanceLoading] = useState(true)
const { balance, project, user, handlePopUpForUser, setBalance, balanceLoading, setBalanceLoading } = props;
const [currency_id, setCurrency_id] = useState<number>();

const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
Expand Down
96 changes: 59 additions & 37 deletions src/components/Project/V2/ExpandableMilestone.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CloudUploadIcon from '@mui/icons-material/CloudUpload';
import ErrorOutlineOutlinedIcon from '@mui/icons-material/ErrorOutlineOutlined';
import { Button, Tooltip } from '@mui/material';
import Accordion from '@mui/material/Accordion';
import AccordionDetails from '@mui/material/AccordionDetails';
Expand All @@ -8,7 +9,7 @@ import { WalletAccount } from '@talismn/connect-wallets';
import axios from 'axios';
import moment from 'moment';
import Image from 'next/image';
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';

import { sendNotification } from '@/utils';
import { initImbueAPIInfo } from '@/utils/polkadot';
Expand All @@ -20,7 +21,6 @@ import Web3WalletModal from '@/components/WalletModal/Web3WalletModal';
import { Milestone, OffchainProjectState, Project, User } from '@/model';
import ChainService, { ImbueChainEvent } from '@/redux/services/chainService';
import {
getMilestoneAttachments,
uploadMilestoneAttachments,
watchChain,
withdrawOffchain,
Expand All @@ -43,7 +43,9 @@ interface ExpandableMilestonProps {
canVote: boolean;
loading: boolean;
targetUser: any;
hasMilestoneAttachments: boolean;
balance: number;
balanceLoading: boolean;
// hasMilestoneAttachments: boolean;
}

const ExpandableMilestone = (props: ExpandableMilestonProps) => {
Expand All @@ -59,7 +61,9 @@ const ExpandableMilestone = (props: ExpandableMilestonProps) => {
setSuccessTitle,
setSuccess,
targetUser,
hasMilestoneAttachments = false
balance,
balanceLoading,
// hasMilestoneAttachments = false
} = props;
const [milestoneKeyInView, setMilestoneKeyInView] = useState<number>(0);
const [submittingMilestone, setSubmittingMilestone] =
Expand All @@ -85,23 +89,23 @@ const ExpandableMilestone = (props: ExpandableMilestonProps) => {
!project.project_in_milestone_voting &&
!milestone?.is_approved;

const [attachments, setAttachment] = useState<any>([]);
// const [attachments, setAttachment] = useState<any>([]);

useEffect(() => {
const getAttachments = async () => {
if (!project?.id || milestone?.milestone_index === undefined) return;
// useEffect(() => {
// const getAttachments = async () => {
// if (!project?.id || milestone?.milestone_index === undefined) return;

const resp = await getMilestoneAttachments(
project.id,
milestone.milestone_index
);
setAttachment(resp);
};
// const resp = await getMilestoneAttachments(
// project.id,
// milestone.milestone_index
// );
// setAttachment(resp);
// };

if(hasMilestoneAttachments){
getAttachments();
}
}, [milestone.milestone_index, project.id]);
// if(hasMilestoneAttachments){
// getAttachments();
// }
// }, [milestone.milestone_index, project.id]);

const [files, setFiles] = useState<File[]>();

Expand Down Expand Up @@ -173,6 +177,7 @@ const ExpandableMilestone = (props: ExpandableMilestonProps) => {
milestone.milestone_index,
fileURLs
);

if (resp) {
await sendNotification(
projectType === 'brief'
Expand Down Expand Up @@ -355,10 +360,8 @@ const ExpandableMilestone = (props: ExpandableMilestonProps) => {
<span className='relative text-sm z-10'>{index + 1}</span>
<div className='w-2 h-2 -rotate-45 bg-[#2400FF] absolute -bottom-0.5 '></div>
</div>
<p className='text-black ml-3 text-2xl'>
{milestone?.name?.length > 40
? milestone.name.substring(0, 40) + ' ...'
: milestone.name}
<p className='text-black ml-3 text-2xl break-words w-11/12'>
{milestone?.name}
</p>
</div>
<p className='col-start-7 col-end-9 text-lg mr-10 ml-4'>
Expand Down Expand Up @@ -406,14 +409,14 @@ const ExpandableMilestone = (props: ExpandableMilestonProps) => {
<p className='mt-5 whitespace-pre-wrap break-words'>
{milestone.description}
</p>
{attachments?.length ? (
{milestone.attachments?.length ? (
<div>
<p className='text-black mt-10 font-semibold text-lg'>
Project Attachments
</p>
<div className='grid grid-cols-6 gap-3'>
{attachments?.length
? attachments.map((attachment: any, index: number) => (
{milestone.attachments?.length
? milestone.attachments.map((attachment: any, index: number) => (
<a
className='col-span-1'
key={index}
Expand Down Expand Up @@ -482,7 +485,7 @@ const ExpandableMilestone = (props: ExpandableMilestonProps) => {
</div>
)}

<div className='w-full mt-7 flex'>
<div className='w-full mt-7'>
{!props?.loading && showVoteButton && (
<Tooltip
followCursor
Expand All @@ -506,17 +509,36 @@ const ExpandableMilestone = (props: ExpandableMilestonProps) => {
</Tooltip>
)}

{showSubmitButton && (
<button
className='primary-btn ml-auto in-dark w-button lg:w-1/5'
style={{ textAlign: 'center' }}
onClick={() =>
handleSubmitMilestone(milestone.milestone_index)
}
>
Submit Milestone
</button>
)}
{
showSubmitButton && (
<div>
<div className='w-full flex'>
<button
className='primary-btn ml-auto in-dark w-button lg:w-1/5'
style={{ textAlign: 'center' }}
onClick={() =>
handleSubmitMilestone(milestone.milestone_index)
}
>
Submit Milestone
</button>
</div>


{
balance === 0 && !balanceLoading && project?.brief_id && (
<div className='lg:flex gap-1 lg:items-center rounded-2xl bg-imbue-coral px-3 py-1 text-sm text-white w-fit ml-auto mt-3 '>
<ErrorOutlineOutlinedIcon className='h-4 w-4 inline' />
<p className='inline'>
No funds have been deposited to the escrow address. If you still want to submit your work the risks are upto you.
</p>
</div>
)
}
</div>

)
}

{isApplicant && milestone.is_approved && (
<button
Expand Down
30 changes: 29 additions & 1 deletion src/components/Project/V2/NoConfidenceVoteBox.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Avatar, AvatarGroup, LinearProgress } from '@mui/material';
import { WalletAccount } from '@talismn/connect-wallets';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import { NoConfidenceVoter } from '@/lib/queryServices/projectQueries';
import { initPolkadotJSAPI } from '@/utils/polkadot';

import VoteModal from '@/components/ReviewModal/VoteModal';
import Web3WalletModal from '@/components/WalletModal/Web3WalletModal';

import { Project, User } from '@/model';
import ChainService from '@/redux/services/chainService';

type MilestoneVoteBoxProps = {
user: User;
Expand Down Expand Up @@ -39,6 +41,32 @@ const NoConfidenceBox = (props: MilestoneVoteBoxProps) => {
setMilestoneKeyInView(milestone_index);
}

useEffect(() => {
const getNoConfidenceVotesChain = async () => {
if (!project.chain_project_id) return

const imbueApi = await initPolkadotJSAPI(
process.env.IMBUE_NETWORK_WEBSOCK_ADDR!
);
const relayChainApi = await initPolkadotJSAPI(
process.env.RELAY_CHAIN_WEBSOCK_ADDR!
);
const allApis = {
imbue: imbueApi,
relayChain: relayChainApi,
};

const chainService = new ChainService(allApis);

const noconfidenceVotes = await chainService.getNoConfidenceVoters(
Number(project.chain_project_id)
);
console.log("🚀 ~ file: NoConfidenceVoteBox.tsx:64 ~ getNoConfidenceVotesChain ~ noconfidenceVotes:", noconfidenceVotes)
}

getNoConfidenceVotesChain()
}, [project.chain_project_id])

return (
<div>
<div className='bg-[#FFDAD8] px-3 rounded-xl py-3 border border-[#FF8C86] mb-4'>
Expand Down
30 changes: 21 additions & 9 deletions src/components/RefundModal/RefundModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,36 @@ import { BiArrowBack } from 'react-icons/bi';
interface VotingModalProps {
setVisible: (_visible: boolean) => void;
setLoading: (_loading: boolean) => void;
handleRefund: () => void;
handleRefund: (_vote: boolean) => Promise<void>;
handleVote: (_vote: boolean) => Promise<void>;
refundOnly: boolean;
}

export default function RefundModal({
setVisible,
handleRefund,
handleVote,
setLoading
setLoading,
refundOnly
}: VotingModalProps) {
console.log("🚀 ~ file: RefundModal.tsx:19 ~ refundOnly:", refundOnly)

const handleNoVote = async (): Promise<void> => {
const handleNo = async (): Promise<void> => {
setLoading(true)
setVisible(false);
await handleVote(false);

if (refundOnly) {
await handleRefund(true)
} else {
await handleVote(false);
}
setLoading(false)
}

const handleYes = async (): Promise<void> => {
setLoading(true)
setVisible(false);
await handleRefund(false)
setLoading(false)
}

Expand All @@ -36,16 +51,13 @@ export default function RefundModal({
</p>
<div className='flex mb-5 space-x-3 w-full items-center mt-9'>
<button
onClick={handleNoVote}
onClick={handleNo}
className='border px-5 py-2 border-imbue-purple text-imbue-purple rounded-full w-[30%]'
>
No
</button>
<button
onClick={() => {
handleRefund()
setVisible(false)
}}
onClick={handleYes}
className='primary-btn ml-auto in-dark w-button w-[70%] '
style={{ textAlign: 'center' }}
>
Expand Down
Loading

0 comments on commit 22bbb0f

Please sign in to comment.