Skip to content

Commit

Permalink
add admin controls on explore page
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed Nov 3, 2023
1 parent fdb6f10 commit 5756258
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 164 deletions.
7 changes: 7 additions & 0 deletions apps/potlock/widget/Index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const ownerId = "potlock.near";
const registryContractId = "registry.potlock.near";

const CREATE_PROJECT_TAB = "createproject";
const EDIT_PROJECT_TAB = "editproject";
Expand Down Expand Up @@ -46,6 +47,7 @@ State.init({
cart: null,
nearToUsd: null,
isCartModalOpen: false,
registryAdmins: null,
});

if (state.nearToUsd === null) {
Expand All @@ -54,6 +56,11 @@ if (state.nearToUsd === null) {
State.update({ nearToUsd: res.body.near.usd });
}

if (state.registryAdmins === null) {
const registryAdmins = Near.view(registryContractId, "get_admins", {});
State.update({ registryAdmins });
}

const tabContentWidget = {
[CREATE_PROJECT_TAB]: "Project.Create",
[EDIT_PROJECT_TAB]: "Project.Create",
Expand Down
158 changes: 87 additions & 71 deletions apps/potlock/widget/Project/Card.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ownerId = "potlock.near";
const donationContractId = "donation.tests.potlock.near"; // TODO: update to donate.potlock.near after testing
const registryContractId = "registry.potlock.near";

const Card = styled.a`
display: flex;
Expand All @@ -17,29 +18,6 @@ const Card = styled.a`
}
`;

// const Banner = styled.div`
// position: relative;
// width: 100%;
// height: 168;
// margin-bottom: 30px;
// `;

// const BannerImage = styled.img`
// width: 100%;
// height: 100%;
// // border-radius: 6px;
// `;

// const ProfileImage = styled.img`
// width: 40px;
// height: 40px;
// border-radius: 50%;
// border: 3px solid white;
// position: absolute;
// bottom: -20px;
// left: 60px;
// `;

const Info = styled.div`
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -116,58 +94,96 @@ const [totalAmount, totalDonors] = useMemo(() => {
];
}, [donationsForProject]);

const PROJECT_STATUSES = [
"Submitted",
"InReview",
"Approved",
"Rejected",
"Graylisted",
"Blacklisted",
];

return (
<Card href={`?tab=project&projectId=${id}`} key={id}>
<Widget
src={`${ownerId}/widget/Project.BannerHeader`}
props={{
...props,
projectId: id,
profile,
profileImageTranslateYPx: 168,
containerStyle: {
paddingLeft: "16px",
},
backgroundStyle: {
objectFit: "cover",
left: 0,
top: 0,
height: "168px",
borderRadius: "6px 6px 0px 0px",
},
imageStyle: {
width: "40px",
height: "40px",
position: "absolute",
bottom: "-10px",
left: "14px",
},
}}
/>
<Info>
<Title>{name}</Title>
<SubTitle>
{description.length > MAX_DESCRIPTION_LENGTH
? description.slice(0, MAX_DESCRIPTION_LENGTH) + "..."
: description}
</SubTitle>
<>
<Card href={`?tab=project&projectId=${id}`} key={id}>
<Widget
src={`${ownerId}/widget/Project.Tags`}
src={`${ownerId}/widget/Project.BannerHeader`}
props={{
...props,
tags,
projectId: id,
profile,
profileImageTranslateYPx: 168,
containerStyle: {
paddingLeft: "16px",
},
backgroundStyle: {
objectFit: "cover",
left: 0,
top: 0,
height: "168px",
borderRadius: "6px 6px 0px 0px",
},
imageStyle: {
width: "40px",
height: "40px",
position: "absolute",
bottom: "-10px",
left: "14px",
},
}}
/>
<Info>
<Title>{name}</Title>
<SubTitle>
{description.length > MAX_DESCRIPTION_LENGTH
? description.slice(0, MAX_DESCRIPTION_LENGTH) + "..."
: description}
</SubTitle>
<Widget
src={`${ownerId}/widget/Project.Tags`}
props={{
...props,
tags,
}}
/>
</Info>
<DonationsInfoContainer>
<DonationsInfoItem>
<Title>{totalDonors || totalDonors === 0 ? totalDonors : "-"}</Title>
<SubTitle>{totalDonors === 1 ? "Donor" : "Donors"}</SubTitle>
</DonationsInfoItem>
<DonationsInfoItem>
<Title>${totalAmount || "-"}</Title>
<SubTitle>Raised</SubTitle>
</DonationsInfoItem>
</DonationsInfoContainer>
</Card>
{props.registryAdmins && props.registryAdmins.includes(context.accountId) && (
<Widget
src={`${ownerId}/widget/Inputs.Select`}
props={{
noLabel: true,
options: PROJECT_STATUSES.map((status) => ({
value: status,
text: status,
})),
value: { text: props.project.status, value: props.project.status },
onChange: (status) => {
if (status.value != project.status) {
Near.call([
{
contractName: registryContractId,
methodName: "admin_set_project_status",
args: { project_id: id, status: status.value },
},
]);
}
},
containerStyles: {
padding: "16px 24px",
},
}}
/>
</Info>
<DonationsInfoContainer>
<DonationsInfoItem>
<Title>{totalDonors || totalDonors === 0 ? totalDonors : "-"}</Title>
<SubTitle>{totalDonors === 1 ? "Donor" : "Donors"}</SubTitle>
</DonationsInfoItem>
<DonationsInfoItem>
<Title>${totalAmount || "-"}</Title>
<SubTitle>Raised</SubTitle>
</DonationsInfoItem>
</DonationsInfoContainer>
</Card>
)}
</>
);
11 changes: 0 additions & 11 deletions apps/potlock/widget/Project/CreateForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,6 @@ return (
value,
text,
})),
// options: [
// Social Impact, NonProfit, Climate, Public Good
// { text: "Social Impact", value: "social-impact" },
// { text: "NonProfit", value: "non-profit" },
// { text: "Climate", value: "climate" },
// { text: "Public Good", value: "public-good" },
// { text: "DeSci", value: "de-sci" },
// { text: "Open Source", value: "open-source" },
// { text: "Community", value: "community" },
// { text: "Education", value: "education" },
// ],
value: { text: CATEGORY_MAPPINGS[state.category] || "", value: state.category },
onChange: (category) => {
State.update({
Expand Down
1 change: 1 addition & 0 deletions apps/potlock/widget/Project/ListPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ if (!state.registeredProjects) {
description: profileData.description ?? "",
bannerImageUrl,
profileImageUrl,
status: project.status,
tags: [profileData.category.text ?? CATEGORY_MAPPINGS[profileData.category] ?? ""], // TODO: change this to get tags from horizon/social
};
return formatted;
Expand Down
7 changes: 7 additions & 0 deletions build/potlock/src/Index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const ownerId = "potlock.near";
const registryContractId = "registry.potlock.near";

const CREATE_PROJECT_TAB = "createproject";
const EDIT_PROJECT_TAB = "editproject";
Expand Down Expand Up @@ -46,6 +47,7 @@ State.init({
cart: null,
nearToUsd: null,
isCartModalOpen: false,
registryAdmins: null,
});

if (state.nearToUsd === null) {
Expand All @@ -54,6 +56,11 @@ if (state.nearToUsd === null) {
State.update({ nearToUsd: res.body.near.usd });
}

if (state.registryAdmins === null) {
const registryAdmins = Near.view(registryContractId, "get_admins", {});
State.update({ registryAdmins });
}

const tabContentWidget = {
[CREATE_PROJECT_TAB]: "Project.Create",
[EDIT_PROJECT_TAB]: "Project.Create",
Expand Down
Loading

0 comments on commit 5756258

Please sign in to comment.