Skip to content

Commit

Permalink
Merge branch 'staging' of github.com:Network-Goods/impact-evaluator-t…
Browse files Browse the repository at this point in the history
…ool into staging
  • Loading branch information
jmoggr committed Aug 23, 2023
2 parents 163e083 + ea261de commit 38b086f
Show file tree
Hide file tree
Showing 26 changed files with 433 additions and 167 deletions.
4 changes: 2 additions & 2 deletions src/components/admin/AdminEditDashboard/AdminEditItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DashboardEvaluation } from "src/lib";
import { evaluation } from "@prisma/client";
import Link from "next/link";
import { returnTime, returnDate } from "src/lib/utils";

Expand All @@ -19,7 +19,7 @@ enum RoundTiming {
type EvaluationItemProps = {
first: boolean;
last: boolean;
evaluation: DashboardEvaluation;
evaluation: evaluation;
};
export const AdminEditItem = ({ evaluation, first, last }: EvaluationItemProps) => {
return (
Expand Down
10 changes: 3 additions & 7 deletions src/components/admin/Evaluation/EvaluationStore.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { create } from "zustand";
import { v4 as uuid } from "uuid";
import { rpc, Submission } from "src/lib";
import { submission } from "@prisma/client";
import { trpc } from "src/lib/trpc";

export interface EvaluationStore {
Expand All @@ -20,7 +21,7 @@ export interface EvaluationStore {
setFormFieldCharCount: (count: number, id: string) => void;
deleteFormField: (id: string) => void;
deleteEvaluation: () => void;
createSubmission: () => Promise<Submission | null>;
createSubmission: () => Promise<submission | null>;
createInvitation: (invitation?: any) => void;
setInvitationCode: (code: string, id: string) => void;
setInvitationCredits: (credits: number, id: string) => void;
Expand Down Expand Up @@ -398,21 +399,16 @@ export const useEvaluationStore = create<EvaluationStore>()((set, get) => ({
});
},

createSubmission: async (): Promise<Submission | null> => {
createSubmission: async (): Promise<submission | null> => {
const evaluation = get().evaluation;

if (get().fetching || !evaluation) {
return null;
}

const newSubmission = Submission.init({
description: "",
evaluation_id: evaluation.id,
name: "",
user_id: null,
github_link: "",
github_handle: "",
links: [],
});

set({
Expand Down
6 changes: 3 additions & 3 deletions src/components/admin/Evaluation/OutcomeModal/OutcomeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const OutcomeModal = ({ handleClose, open, submission, store }: OutcomeModalProp
specs: storeSubmissionExists?.description.specs,
github_link: storeSubmissionExists?.github_link,
links: storeSubmissionExists?.links || [],
githubHandle: storeSubmissionExists?.github_handle || "",
github_handle: storeSubmissionExists?.github_handle || "",
user_id: storeSubmissionExists?.user_id,
});

Expand All @@ -56,15 +56,15 @@ const OutcomeModal = ({ handleClose, open, submission, store }: OutcomeModalProp
specs: storeSubmissionExists?.description.specs,
github_link: storeSubmissionExists?.github_link,
links: storeSubmissionExists?.links || [],
githubHandle: storeSubmissionExists?.github_handle || "",
github_handle: storeSubmissionExists?.github_handle || "",
user_id: storeSubmissionExists?.user_id,
});
}, [storeSubmissionExists]);

const isDisabled =
!formInputs.name ||
!formInputs.github_link ||
!formInputs.githubHandle ||
!formInputs.github_handle ||
!formInputs.user_id ||
!submissionFormCustomFieldsCheck(formInputs, submission?.id);
return (
Expand Down
7 changes: 4 additions & 3 deletions src/components/dashboard/DashboardStore.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { create } from "zustand";
import { Evaluation, rpc, DashboardEvaluation } from "src/lib";
import { evaluation } from "@prisma/client";
import { trpc } from "src/lib/trpc";

export interface DashboardStore {
fetching: boolean;
error?: any;
evaluations: DashboardEvaluation[];
load: () => void;
createEvaluation: () => Promise<Evaluation | Error>;
createEvaluation: () => Promise<evaluation | Error>;
}

export const useDashboardStore = create<DashboardStore>()((set, get) => ({
Expand All @@ -30,8 +31,8 @@ export const useDashboardStore = create<DashboardStore>()((set, get) => ({
});
},

createEvaluation: async (): Promise<Evaluation | Error> => {
const newEvaluation: Evaluation = {
createEvaluation: async (): Promise<evaluation | Error> => {
const newEvaluation: evaluation = {
...Evaluation.init(),
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/roundDetails/RoundDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import EvaluationLinkButton from "../dashboard/EvaluationLinkButton";
import SmallTitle from "../shared/SmallTitle";
import Title from "../shared/Title";
import VotingTableBody from "../voting/VotingTableBody";
import { Submission, VotingTableBodySubmission } from "src/lib";
import { VotingTableBodySubmission } from "src/lib";
import Add from "public/images/svg/Add";
import QuadraticVotingModal from "../voting/QuadraticVotingModal";
import parse from "html-react-parser";
Expand Down
11 changes: 5 additions & 6 deletions src/components/roundDetails/RoundDetailsStore.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { create } from "zustand";
import { v4 as uuid } from "uuid";
import { rpc, Submission } from "src/lib";
import { submission } from "@prisma/client";
import { trpc } from "src/lib/trpc";

export interface RoundDetailsStore {
fetching: boolean;
evaluation?: any;
submissions?: Submission[];
evaluation_field?: any;
submissions?: submission[];
evaluationID?: string;
userID?: string;
githubHandle?: string;
load: (userID: string, evaluationID: string, githubHandle: string) => void;
deleteSubmission: (submissionID: string) => void;
createSubmission: () => Promise<Submission | null>;
createSubmission: () => Promise<submission | null>;
}

export const useRoundDetailsStore = create<RoundDetailsStore>()((set, get) => ({
Expand All @@ -31,9 +31,8 @@ export const useRoundDetailsStore = create<RoundDetailsStore>()((set, get) => ({
}

set({
evaluation: data.evaluation[0],
evaluation: data.evaluation,
submissions: data.submissions,
evaluation_field: data.evaluation_field,
evaluationID: evaluationID,
userID: userID,
githubHandle: githubHandle,
Expand All @@ -60,7 +59,7 @@ export const useRoundDetailsStore = create<RoundDetailsStore>()((set, get) => ({
}
});
},
createSubmission: async (): Promise<Submission | null> => {
createSubmission: async (): Promise<submission | null> => {
const evaluationID = get().evaluationID;
const userID = get().userID;
const githubHandle = get().githubHandle;
Expand Down
10 changes: 5 additions & 5 deletions src/components/shared/Submission.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Add from "public/images/svg/Add";
import Delete from "public/images/svg/Delete";
import Edit from "public/images/svg/Edit";
import { Submission as SubmissionType, SubmissionFormInputs } from "src/lib";
import { SubmissionFormLinkInputs } from "src/lib";
import { SubmissionFormInputs, SubmissionFormLinkInputs } from "src/lib";
import { submission } from "@prisma/client";

type SubmissionProps = {
store: any;
Expand All @@ -11,7 +11,7 @@ type SubmissionProps = {
setFormInputs: any;
isGithubHandleChecked?: boolean;
setIsGithubHandleChecked?: any;
submission?: SubmissionType;
submission?: submission;
submission_id: string | string[] | undefined;
};

Expand Down Expand Up @@ -229,8 +229,8 @@ export default function Submission({
className="text-base appearance-none border border-gray rounded-lg w-full py-2 px-3 mt-1 font-medium disabled:text-gray focus:outline-none"
type="text"
name="githubHandle"
value={formInputs.githubHandle || ""}
onChange={(e) => handleFormChange(e, "githubHandle")}
value={formInputs.github_handle || ""}
onChange={(e) => handleFormChange(e, "github_handle")}
onBlur={
!submission
? (e) => store.setGithubHandle(e.target.value)
Expand Down
8 changes: 5 additions & 3 deletions src/components/submission/SubmissionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export default function SubmissionPage() {
specs: store.submission?.description.specs,
github_link: store.submission?.github_link,
links: store.submission?.links || [],
githubHandle: isGithubHandleChecked ? store.submission?.github_handle : "",
github_handle: isGithubHandleChecked ? store.submission?.github_handle : "",
user_id: store.submission?.user_id,
});

const handleSubmitModal = () => {
Expand Down Expand Up @@ -83,15 +84,16 @@ export default function SubmissionPage() {
specs: store.submission?.description.specs,
github_link: store.submission?.github_link,
links: store.submission?.links,
githubHandle: store.submission?.github_handle,
github_handle: store.submission?.github_handle,
user_id: store.submission?.user_id,
});
if (githubHandleFromProfile) setIsGithubHandleChecked(githubHandleFromProfile === store.submission?.github_handle);
}, [store.submission]);

const isSubmitButtonDisabled =
!formInputs.name ||
!formInputs.github_link ||
(isGithubHandleChecked ? !githubHandleFromProfile : !formInputs.githubHandle) ||
(isGithubHandleChecked ? !githubHandleFromProfile : !formInputs.github_handle) ||
(formInputs.links && formInputs.links.some((link) => !link.name || !link.value)) ||
!submissionFormCustomFieldsCheck(formInputs, submission_id);

Expand Down
10 changes: 4 additions & 6 deletions src/components/submission/SubmissionStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { create } from "zustand";
import { v4 as uuid } from "uuid";
import { Evaluation, rpc, Submission } from "src/lib";
import { trpc } from "src/lib/trpc";
import { submission } from "@prisma/client";

export interface SubmissionStore {
fetching: boolean;
submission?: any;
Expand All @@ -17,7 +19,7 @@ export interface SubmissionStore {
createSubmissionLink: () => void;
deleteSubmissionLink: (index: number) => void;
setSubmission: () => void;
createSubmission: (evaluation_id: string, user_id: string) => Promise<Submission | null>;
createSubmission: (evaluation_id: string, user_id: string) => Promise<submission | null>;
}

export const useSubmissionStore = create<SubmissionStore>()((set, get) => ({
Expand Down Expand Up @@ -320,21 +322,17 @@ export const useSubmissionStore = create<SubmissionStore>()((set, get) => ({
}
});
},
createSubmission: async (evaluation_id: string, user_id: string): Promise<Submission | null> => {
createSubmission: async (evaluation_id: string, user_id: string): Promise<submission | null> => {
const githubHandle = get().githubHandle;

if (get().fetching || !githubHandle) {
return null;
}

const newSubmission = Submission.init({
description: "",
evaluation_id: evaluation_id,
name: "",
user_id: user_id,
github_handle: githubHandle,
github_link: "",
links: [],
});

const res = await trpc().user.createSubmission.mutate(newSubmission);
Expand Down
7 changes: 4 additions & 3 deletions src/components/voting/VotingStore.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { create } from "zustand";
import { Submission, rpc } from "src/lib";
import { rpc, Submission } from "src/lib";
import { trpc } from "src/lib/trpc";
import { submission } from "@prisma/client";

function calculateAvailableCredits(votes: SubmissionVotes) {
let usedCredits = 0;
Expand All @@ -17,7 +18,7 @@ export type VotingStore = {
votes: SubmissionVotes;
evaluator: { id: string; voice_credits: number } | null;
evaluation: any | null;
submissions: Submission[];
submissions: submission[];
expandedSubmissions: { [submissionId: string]: boolean };
availableCredits: number;
allocatedCredits: number;
Expand Down Expand Up @@ -50,7 +51,7 @@ export const useVotingStore = create<VotingStore>()((set, get) => ({
console.error(`ERROR -- rpc call getVotingStore failed. evaluation_id: ${evaluation_id}`, data);
return;
}

console.log("data", data);
data.submissions.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));

set({
Expand Down
30 changes: 16 additions & 14 deletions src/components/voting/VotingTableBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ type VotingTableBodyProps = {
};

export default function VotingTableBody({ idx, project, submissions, search }: VotingTableBodyProps) {
project.fields.sort((a: any, b: any) => a.field_order - b.field_order);
project.submission_field.sort((a: any, b: any) => a.field_order - b.field_order);

const linksArray = Array.isArray(project.links) ? project.links : [];

return (
<div
Expand All @@ -22,25 +24,25 @@ export default function VotingTableBody({ idx, project, submissions, search }: V
<div className="border border-gray w-full h-[3px]"></div>
<div className="flex flex-col md:flex-row pt-5">
<div className="md:w-[70%] pr-12">
{project.fields.map((field: any) => (
<div key={field.field_id}>
{project.submission_field.map((field: any) => (
<div key={field.fields_id}>
<div className="font-bold">{field.heading}</div>
<p className="text-sm mb-3 whitespace-pre-wrap">{field.field_body}</p>
</div>
))}
</div>
<div className="md:w-[30%] md:border-l md:border-gray md:pl-6">
<div className="font-bold">{`Project Link${project.links.length > 1 ? "s" : ""}`}</div>
<div className="flex flex-col">
<VotingTableLink title="Github" link={project.github_link} />
{project.links
? project.links.map((link: any, idx: any) => (
<div key={idx}>
<VotingTableLink title={link.name} link={link.value} />
</div>
))
: null}
</div>
<div className="font-bold">{linksArray.length > 1 ? "Project Links" : "Project Link"}</div>
{linksArray.length > 0 && (
<div className="flex flex-col">
{project.github_link ? <VotingTableLink title="Github" link={project.github_link} /> : null}
{linksArray.map((link: any, idx: number) => (
<div key={idx}>
<VotingTableLink title={link.name} link={link.value} />
</div>
))}
</div>
)}
</div>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/lib/UserProfileStore.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { create } from "zustand";
import { rpc, UserProfile } from "../lib";
import { rpc } from "../lib";
import { user } from "@prisma/client";
import { trpc } from "../lib/trpc";

export type UserProfileStore = {
profile?: UserProfile;
profile?: user;
login: () => void;
logout: () => void;
isAdmin: () => boolean;
Expand Down
Loading

0 comments on commit 38b086f

Please sign in to comment.