Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Staging => mian"" #111

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/PotCard/PotCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ type Props = {

const PotCard = ({ potId }: Props) => {
const potConfig: PotDetail = PotSDK.getConfig(potId);

if (!potConfig)
return (
<Card style={{ justifyContent: "center", alignItems: "center" }}>
{potConfig == null ? (
{potConfig === null ? (
<div className="spinner-border text-secondary" role="status" />
) : (
<div>Pot {potId} not found.</div>
Expand Down Expand Up @@ -55,6 +54,7 @@ const PotCard = ({ potId }: Props) => {

return (
<Card
key={potId}
href={hrefWithParams(`?tab=pot&potId=${potId}`)}
data-testid={applicationOpen ? "active-pot" : "inactive-pot"}
>
Expand Down
44 changes: 21 additions & 23 deletions src/pages/Project/NavPages/Pots/Pots.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import { useParams, useState } from "alem";
import { useEffect, useMemo, useParams, useState } from "alem";
import PotSDK from "@app/SDK/pot";
import PotFactorySDK from "@app/SDK/potfactory";
import PotCard from "@app/components/PotCard/PotCard";
import ListSection from "@app/pages/Projects/components/ListSection";
import { Container, NoResults } from "./styles";

const Pots = () => {
const pots = PotFactorySDK.getPots();
const { projectId } = useParams();

const [potIds, setPotIds] = useState<any>(null); // ids[] of pots that approved project
const [loading, setLoading] = useState(true); // ids[] of pots that approved project
const POT_STATUS = ["Approved", "pending"];

const getApprovedApplications = (potId: any) =>
PotSDK.asyncGetApprovedApplications(potId)
.then((applications: any) => {
if (applications.some((app: any) => app.project_id === projectId)) {
setPotIds([...(potIds || []), potId]);
}
if (pots[pots.length - 1].id === potId) setLoading(false);
})
.catch(() => console.log(`Error fetching approved applications for ${potId}`));
const [potIds, setPotIds] = useState<any>(null); // ids[] of pots that approved project
// const [loading, setLoading] = useState(true);

if (pots && loading) {
pots.forEach((pot: any) => {
getApprovedApplications(pot.id);
});
}
useEffect(() => {
if (pots && !potIds) {
const applicationsPrmomises = pots.map(({ id }: any) => PotSDK.asyncGetApplicationByProjectId(id, projectId));
Promise.allSettled(applicationsPrmomises).then((applications: any) => {
const enrolledPots: any = [];
applications.forEach((obj: any, idx: number) => {
if (POT_STATUS.includes(obj.value.status)) {
enrolledPots.push(pots[idx]);
}
});
setPotIds(enrolledPots);
});
}
}, [pots]);

return loading ? (
return potIds === null ? (
"Loading..."
) : potIds.length ? (
<Container>
{potIds.map((potId: string) => (
<PotCard {...{ potId, tab: "pots" }} />
))}
</Container>
<ListSection maxCols={3} items={potIds} renderItem={(pot: any) => <PotCard potId={pot.id} key={pot.id} />} />
) : (
<NoResults>
<div className="text">This project has not participated in any pots yet.</div>
Expand Down
1 change: 1 addition & 0 deletions src/pages/Project/NavPages/Pots/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from "styled-components";
export const Container = styled.div`
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
> div {
padding-top: 0rem;
}
Expand Down
Loading