Skip to content

Commit

Permalink
fix admin view for project detail
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed Feb 5, 2024
1 parent 0ba9db7 commit 8256770
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
8 changes: 7 additions & 1 deletion apps/potlock/widget/Index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ State.init({
isCartModalOpen: false,
isNavMenuOpen: false,
registryConfig: null,
userIsRegistryAdmin: null,
registeredProjects: null,
donnorProjectId: null,
amount: null,
Expand Down Expand Up @@ -148,7 +149,12 @@ if (!state.registeredProjects) {

if (state.registryConfig === null) {
const registryConfig = Near.view(registryContractId, "get_config", {});
State.update({ registryConfig });
if (registryConfig) {
State.update({
registryConfig,
userIsRegistryAdmin: registryConfig.admins.includes(context.accountId),
});
}
}

const tabContentWidget = {
Expand Down
18 changes: 8 additions & 10 deletions apps/potlock/widget/Project/Detail.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
const { ownerId } = props;
const { ownerId, projectId, userIsRegistryAdmin } = props;
const registryId = "registry.potlock.near";

const profile = props.profile ?? Social.getr(`${props.projectId}/profile`);
const profile = props.profile ?? Social.getr(`${projectId}/profile`);

const projects = props.projects ?? Near.view(registryId, "get_projects", {});
const project = Near.view(registryId, "get_project_by_id", { project_id: projectId });

if (!profile || !projects) {
if (!profile || !project) {
return "Loading";
}

const registeredProject = projects.find(
(project) => project.id == props.projectId && project.status == "Approved"
);
const projectIsViewable = project.status === "Approved" || userIsRegistryAdmin;

const name = profile.name || "No-name profile";
const image = profile.image;
Expand Down Expand Up @@ -61,14 +59,14 @@ props.navOptions = [
id: "home",
disabled: false,
source: `${ownerId}/widget/Project.About`,
href: `?tab=project&projectId=${props.projectId}&nav=home`,
href: `?tab=project&projectId=${projectId}&nav=home`,
},
{
label: "Social Feed",
id: "feed",
disabled: false,
source: `${ownerId}/widget/Project.Feed`,
href: `?tab=project&projectId=${props.projectId}&nav=feed`,
href: `?tab=project&projectId=${projectId}&nav=feed`,
},
{
label: "Pots",
Expand All @@ -94,7 +92,7 @@ const profileImageTranslateYPx = 220;

return (
<Wrapper>
{!registeredProject ? (
{!projectIsViewable ? (
<div style={{ textAlign: "center", paddingTop: "12px" }}>Project not found</div>
) : (
<>
Expand Down
11 changes: 3 additions & 8 deletions apps/potlock/widget/Project/ListPage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ownerId } = props;
const { ownerId, userIsRegistryAdmin } = props;
const registryId = "registry.potlock.near";

const IPFS_BASE_URL = "https://nftstorage.link/ipfs/";
Expand Down Expand Up @@ -100,17 +100,12 @@ const InfoCardsContainer = styled.div`
}
`;

console.log("props in listpage: ", props);
const userIsAdmin = props.registryConfig && props.registryConfig.admins.includes(context.accountId);
console.log("user is admin? ", userIsAdmin);
console.log("props.registeredProjects length: ", props.registeredProjects.length);

const projects = useMemo(
() =>
userIsAdmin
userIsRegistryAdmin
? props.registeredProjects
: props.registeredProjects.filter((project) => project.status === "Approved"),
[props.registeredProjects, userIsAdmin]
[props.registeredProjects, userIsRegistryAdmin]
);

const [totalDonations, totalDonors] = useMemo(() => {
Expand Down

0 comments on commit 8256770

Please sign in to comment.