Skip to content

Commit

Permalink
fix: grantType coming as string
Browse files Browse the repository at this point in the history
  • Loading branch information
amaurymagalhaes committed Nov 4, 2024
1 parent d88cdae commit 3044174
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 106 deletions.
37 changes: 37 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
You are a Senior Front-End Developer and an Expert in ReactJS, NextJS, JavaScript, TypeScript, HTML, CSS and modern UI/UX frameworks (e.g., TailwindCSS, Shadcn, Radix). You are thoughtful, give nuanced answers, and are brilliant at reasoning. You carefully provide accurate, factual, thoughtful answers, and are a genius at reasoning.

- Follow the user’s requirements carefully & to the letter.
- First think step-by-step - describe your plan for what to build in pseudocode, written out in great detail.
- Confirm, then write code!
- Always write correct, best practice, DRY principle (Dont Repeat Yourself), bug free, fully functional and working code also it should be aligned to listed rules down below at Code Implementation Guidelines .
- Focus on easy and readability code, over being performant.
- Fully implement all requested functionality.
- Leave NO todo’s, placeholders or missing pieces.
- Ensure code is complete! Verify thoroughly finalised.
- Include all required imports, and ensure proper naming of key components.
- Be concise Minimize any other prose.
- If you think there might not be a correct answer, you say so.
- If you do not know the answer, say so, instead of guessing.

### Coding Environment

The user asks questions about the following coding languages:

- ReactJS
- NextJS
- JavaScript
- TypeScript
- TailwindCSS
- HTML
- CSS

### Code Implementation Guidelines

Follow these rules when you write code:

- Use early returns whenever possible to make the code more readable.
- Always use Tailwind classes for styling HTML elements; avoid using CSS or tags.
- Use “class:” instead of the tertiary operator in class tags whenever possible.
- Use descriptive variable and function/const names. Also, event functions should be named with a “handle” prefix, like “handleClick” for onClick and “handleKeyDown” for onKeyDown.
- Implement accessibility features on elements. For example, a tag should have a tabindex=“0”, aria-label, on:click, and on:keydown, and similar attributes.
- Use consts instead of functions, for example, “const toggle = () =>”. Also, define a type if possible.
93 changes: 46 additions & 47 deletions components/Pages/ProgramRegistry/AddProgram.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
"use client";
import { z } from "zod";
import type { SubmitHandler } from "react-hook-form";
import { Controller, useForm } from "react-hook-form";
import toast from "react-hot-toast";
import { zodResolver } from "@hookform/resolvers/zod";
import { useState, useEffect } from "react";
import { MESSAGES } from "@/utilities/messages";
import { CalendarIcon, ChevronLeftIcon } from "@heroicons/react/24/solid";
import { Button } from "@/components/Utilities/Button";
import Link from "next/link";
import { PAGES } from "@/utilities/pages";
import { getWalletClient } from "@wagmi/core";
import { walletClientToSigner } from "@/utilities/eas-wagmi-utils";
import { useAccount, useSwitchChain } from "wagmi";
import { envVars } from "@/utilities/enviromentVars";
import { useRouter } from "next/navigation";
import { CommunitiesSelect } from "@/components/CommunitiesSelect";
import {
ICommunityResponse
} from "@show-karma/karma-gap-sdk/core/class/karma-indexer/api/types";
import { getGapClient, useGap } from "@/hooks";
import { gapIndexerApi } from "@/utilities/gapIndexerApi";
import { useAuthStore } from "@/store/auth";
import { useConnectModal } from "@rainbow-me/rainbowkit";
import { registryHelper } from "./helper";
import { SearchDropdown } from "./SearchDropdown";
import { appNetwork } from "@/utilities/network";
import { chainImgDictionary } from "@/utilities/chainImgDictionary";
import { cn } from "@/utilities/tailwind";
import { Telegram2Icon, WebsiteIcon } from "@/components/Icons";
import { BlogIcon } from "@/components/Icons/Blog";
import { Discord2Icon } from "@/components/Icons/Discord2";
import { DiscussionIcon } from "@/components/Icons/Discussion";
import { OrganizationIcon } from "@/components/Icons/Organization";
import fetchData from "@/utilities/fetchData";
import { INDEXER } from "@/utilities/indexer";
import { GrantProgram } from "./ProgramList";
import { Twitter2Icon } from "@/components/Icons/Twitter2";
import { Discord2Icon } from "@/components/Icons/Discord2";
import { AlloBase } from "@show-karma/karma-gap-sdk/core/class/GrantProgramRegistry/Allo";
import { StatusDropdown } from "./StatusDropdown";
import { config } from "@/utilities/wagmi/config";
import { Button } from "@/components/Utilities/Button";
import { errorManager } from "@/components/Utilities/errorManager";
import { useGap } from "@/hooks";
import { useAuthStore } from "@/store/auth";
import { useStepper } from "@/store/modals/txStepper";
import { useRegistryStore } from "@/store/registry";
import { Popover } from "@headlessui/react";
import { chainImgDictionary } from "@/utilities/chainImgDictionary";
import { walletClientToSigner } from "@/utilities/eas-wagmi-utils";
import { envVars } from "@/utilities/enviromentVars";
import fetchData from "@/utilities/fetchData";
import { formatDate } from "@/utilities/formatDate";
import { DayPicker } from "react-day-picker";
import { errorManager } from "@/components/Utilities/errorManager";
import { sanitizeObject } from "@/utilities/sanitize";
import { gapIndexerApi } from "@/utilities/gapIndexerApi";
import { INDEXER } from "@/utilities/indexer";
import { MESSAGES } from "@/utilities/messages";
import { appNetwork } from "@/utilities/network";
import { PAGES } from "@/utilities/pages";
import { urlRegex } from "@/utilities/regexs/urlRegex";
import { te } from "date-fns/locale";
import { sanitizeObject } from "@/utilities/sanitize";
import { cn } from "@/utilities/tailwind";
import { config } from "@/utilities/wagmi/config";
import { Popover } from "@headlessui/react";
import { CalendarIcon, ChevronLeftIcon } from "@heroicons/react/24/solid";
import { zodResolver } from "@hookform/resolvers/zod";
import { useConnectModal } from "@rainbow-me/rainbowkit";
import { AlloBase } from "@show-karma/karma-gap-sdk/core/class/GrantProgramRegistry/Allo";
import { ICommunityResponse } from "@show-karma/karma-gap-sdk/core/class/karma-indexer/api/types";
import { getWalletClient } from "@wagmi/core";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { DayPicker } from "react-day-picker";
import type { SubmitHandler } from "react-hook-form";
import { Controller, useForm } from "react-hook-form";
import toast from "react-hot-toast";
import { useAccount, useSwitchChain } from "wagmi";
import { z } from "zod";
import { registryHelper } from "./helper";
import { GrantProgram } from "./ProgramList";
import { SearchDropdown } from "./SearchDropdown";
import { StatusDropdown } from "./StatusDropdown";

const labelStyle = "text-sm font-bold text-[#344054] dark:text-zinc-100";
const inputStyle =
Expand Down Expand Up @@ -184,7 +181,6 @@ export default function AddProgram({
});
const { gap } = useGap();


const [allCommunities, setAllCommunities] = useState<ICommunityResponse[]>(
[]
);
Expand All @@ -204,7 +200,6 @@ export default function AddProgram({
};

if (allCommunities.length === 0) fetchCommunities();

}, [allCommunities]);

const {
Expand Down Expand Up @@ -248,7 +243,11 @@ export default function AddProgram({
ecosystems: programToEdit?.metadata?.ecosystems || [],
organizations: programToEdit?.metadata?.organizations || [],
networks: programToEdit?.metadata?.networks || [],
grantTypes: programToEdit?.metadata?.grantTypes || [],
grantTypes: Array.isArray(programToEdit?.metadata?.grantTypes)
? programToEdit?.metadata?.grantTypes
: programToEdit?.metadata?.grantTypes
? [programToEdit?.metadata?.grantTypes]
: [],
networkToCreate: programToEdit?.chainID || 0,
grantsSite: programToEdit?.metadata?.socialLinks?.grantsSite,
platformsUsed: programToEdit?.metadata?.platformsUsed || [],
Expand Down Expand Up @@ -470,7 +469,7 @@ export default function AddProgram({
while (retries > 0) {
await fetchData(
INDEXER.REGISTRY.GET_ALL +
`?programId=${programToEdit?.programId}`
`?programId=${programToEdit?.programId}`
)
.then(async ([res]) => {
const hasUpdated =
Expand Down Expand Up @@ -822,7 +821,7 @@ export default function AddProgram({
{errors.networks?.message}
</p>
</div>
<div className="flex w-full flex-col gap-1">
<div className="flex w-full flex-col gap-1">
<label htmlFor="program-types" className={labelStyle}>
Funding Mechanisms
</label>
Expand Down Expand Up @@ -866,7 +865,7 @@ export default function AddProgram({
</label>
<CommunitiesSelect
onSelectFunction={(community: ICommunityResponse) => {
onChangeGeneric(community?.uid, "communityRef")
onChangeGeneric(community?.uid, "communityRef");
}}
list={allCommunities}
selected={watch("communityRef")}
Expand All @@ -878,7 +877,7 @@ export default function AddProgram({
</p>
</div>
{programToEdit && (
<div className="flex w-full flex-col justify-between gap-2">
<div className="flex w-full flex-col gap-1">
<label htmlFor="program-status" className={labelStyle}>
Status
</label>
Expand Down
64 changes: 31 additions & 33 deletions components/Pages/ProgramRegistry/ManagePrograms.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
"use client";
import React, { Dispatch, useMemo } from "react";
import { useState, useEffect } from "react";
import { Spinner } from "@/components/Utilities/Spinner";
import fetchData from "@/utilities/fetchData";
import { INDEXER } from "@/utilities/indexer";
import { GrantProgram } from "@/components/Pages/ProgramRegistry/ProgramList";
import AddProgram from "@/components/Pages/ProgramRegistry/AddProgram";
import { ManageProgramList } from "@/components/Pages/ProgramRegistry/ManageProgramList";
import toast from "react-hot-toast";
import { MyProgramList } from "@/components/Pages/ProgramRegistry/MyProgramList";
import { ProgramDetailsDialog } from "@/components/Pages/ProgramRegistry/ProgramDetailsDialog";
import { GrantProgram } from "@/components/Pages/ProgramRegistry/ProgramList";
import { registryHelper } from "@/components/Pages/ProgramRegistry/helper";
import { Button } from "@/components/Utilities/Button";
import { useQueryState } from "nuqs";
import AddProgram from "@/components/Pages/ProgramRegistry/AddProgram";
import { useAccount, useSwitchChain } from "wagmi";
import Pagination from "@/components/Utilities/Pagination";
import { useAuthStore } from "@/store/auth";
import { useConnectModal } from "@rainbow-me/rainbowkit";
import { useStepper } from "@/store/modals/txStepper";
import { useRegistryStore } from "@/store/registry";
import { isMemberOfProfile } from "@/utilities/allo/isMemberOf";
import { useSigner } from "@/utilities/eas-wagmi-utils";
import fetchData from "@/utilities/fetchData";
import { INDEXER } from "@/utilities/indexer";
import { PAGES } from "@/utilities/pages";
import { checkIsPoolManager } from "@/utilities/registry/checkIsPoolManager";
import {
ChevronLeftIcon,
MagnifyingGlassIcon,
} from "@heroicons/react/24/solid";
import Link from "next/link";
import { PAGES } from "@/utilities/pages";
import { envVars } from "@/utilities/enviromentVars";
import { getWalletClient } from "@wagmi/core";
import { useSigner, walletClientToSigner } from "@/utilities/eas-wagmi-utils";
import { AlloBase } from "@show-karma/karma-gap-sdk/core/class/GrantProgramRegistry/Allo";
import {
Address,
ApplicationMetadata,
} from "@show-karma/karma-gap-sdk/core/class/types/allo";
import { AlloContracts } from "@show-karma/karma-gap-sdk/core/consts";
import Pagination from "@/components/Utilities/Pagination";
import { useConnectModal } from "@rainbow-me/rainbowkit";
import { useQuery } from "@tanstack/react-query";
import debounce from "lodash.debounce";
import { ProgramDetailsDialog } from "@/components/Pages/ProgramRegistry/ProgramDetailsDialog";
import { registryHelper } from "@/components/Pages/ProgramRegistry/helper";
import { config } from "@/utilities/wagmi/config";
import { isMemberOfProfile } from "@/utilities/allo/isMemberOf";
import { checkIsPoolManager } from "@/utilities/registry/checkIsPoolManager";
import { MyProgramList } from "@/components/Pages/ProgramRegistry/MyProgramList";
import { useStepper } from "@/store/modals/txStepper";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
import { useRegistryStore } from "@/store/registry";
import { useQuery } from "@tanstack/react-query";
import { useQueryState } from "nuqs";
import React, { Dispatch, useEffect, useState } from "react";
import toast from "react-hot-toast";
import { useAccount, useSwitchChain } from "wagmi";

import { errorManager } from "@/components/Utilities/errorManager";
import { sanitizeObject } from "@/utilities/sanitize";
import { LoadingProgramTable } from "./Loading/Programs";
import { SearchDropdown } from "./SearchDropdown";

Expand Down Expand Up @@ -186,6 +174,11 @@ export const ManagePrograms = () => {
);
if (error) throw Error(error);
if (data) {
data.forEach((program: GrantProgram) => {
if (typeof program.metadata?.grantTypes === "string") {
program.metadata.grantTypes = [program.metadata.grantTypes];
}
});
setSelectedProgram(data);
}
} catch (error: any) {
Expand Down Expand Up @@ -231,6 +224,11 @@ export const ManagePrograms = () => {

const [res, error] = await fetchData(url);
if (!error && res) {
res.programs.forEach((program: GrantProgram) => {
if (typeof program.metadata?.grantTypes === "string") {
program.metadata.grantTypes = [program.metadata.grantTypes];
}
});
return {
programs: res.programs as GrantProgram[],
count: res.count as number,
Expand Down
18 changes: 8 additions & 10 deletions components/Pages/ProgramRegistry/ProgramDetailsDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
"use client";
/* eslint-disable @next/next/no-img-element */
import { FC, Fragment } from "react";
import { Dialog, Transition } from "@headlessui/react";
import { GrantProgram } from "./ProgramList";
import formatCurrency from "@/utilities/formatCurrency";
import { ExternalLink } from "@/components/Utilities/ExternalLink";
import {
BlogIcon,
Discord2Icon,
Expand All @@ -13,13 +8,16 @@ import {
Telegram2Icon,
Twitter2Icon,
} from "@/components/Icons";
import Image from "next/image";
import { ReadMore } from "@/utilities/ReadMore";
import { XMarkIcon } from "@heroicons/react/24/solid";
import { registryHelper } from "./helper";
import { Button } from "@/components/Utilities/Button";
import { MarkdownPreview } from "@/components/Utilities/MarkdownPreview";
import { ExternalLink } from "@/components/Utilities/ExternalLink";
import formatCurrency from "@/utilities/formatCurrency";
import { cn } from "@/utilities/tailwind";
import { Dialog, Transition } from "@headlessui/react";
import { XMarkIcon } from "@heroicons/react/24/solid";
import Image from "next/image";
import { FC, Fragment } from "react";
import { registryHelper } from "./helper";
import { GrantProgram } from "./ProgramList";

type ProgramDetailsDialogProps = {
program: GrantProgram;
Expand Down
37 changes: 21 additions & 16 deletions components/Pages/ProgramRegistry/ProgramsExplorer.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
"use client";
/* eslint-disable @next/next/no-img-element */
import React, { Dispatch, useMemo } from "react";
import { useState, useEffect } from "react";
import { MagnifyingGlassIcon } from "@heroicons/react/20/solid";
import { CheckIcon } from "@heroicons/react/24/solid";
import { Spinner } from "@/components/Utilities/Spinner";
import debounce from "lodash.debounce";
import fetchData from "@/utilities/fetchData";
import { INDEXER } from "@/utilities/indexer";
import { registryHelper } from "@/components/Pages/ProgramRegistry/helper";
import { ProgramDetailsDialog } from "@/components/Pages/ProgramRegistry/ProgramDetailsDialog";
import {
GrantProgram,
ProgramList,
} from "@/components/Pages/ProgramRegistry/ProgramList";
import { registryHelper } from "@/components/Pages/ProgramRegistry/helper";
import { SearchDropdown } from "@/components/Pages/ProgramRegistry/SearchDropdown";
import { useQueryState } from "nuqs";
import { useAccount } from "wagmi";
import Pagination from "@/components/Utilities/Pagination";
import { ProgramDetailsDialog } from "@/components/Pages/ProgramRegistry/ProgramDetailsDialog";
import { useRegistryStore } from "@/store/registry";
import { isMemberOfProfile } from "@/utilities/allo/isMemberOf";
import fetchData from "@/utilities/fetchData";
import { INDEXER } from "@/utilities/indexer";
import { checkIsPoolManager } from "@/utilities/registry/checkIsPoolManager";
import { useSearchParams } from "next/navigation";
import { MagnifyingGlassIcon } from "@heroicons/react/20/solid";
import { CheckIcon } from "@heroicons/react/24/solid";
import { useQuery } from "@tanstack/react-query";
import { ExternalLink } from "@/components/Utilities/ExternalLink";
import { useRegistryStore } from "@/store/registry";
import debounce from "lodash.debounce";
import { useSearchParams } from "next/navigation";
import { useQueryState } from "nuqs";
import React, { Dispatch, useEffect, useState } from "react";
import { useAccount } from "wagmi";

import { errorManager } from "@/components/Utilities/errorManager";
import { LoadingPrograms, LoadingProgramTable } from "./Loading/Programs";
import { LoadingProgramTable } from "./Loading/Programs";
import { ProgramHeader } from "./ProgramHeader";

const statuses = ["Active", "Inactive"];
Expand Down Expand Up @@ -197,6 +194,11 @@ export const ProgramsExplorer = () => {
if (error) {
throw new Error(error);
}
res.programs.forEach((program: GrantProgram) => {
if (typeof program.metadata?.grantTypes === "string") {
program.metadata.grantTypes = [program.metadata.grantTypes];
}
});
return res;
},
});
Expand All @@ -215,6 +217,9 @@ export const ProgramsExplorer = () => {
);
if (data) {
setSelectedProgram(data);
if (typeof data.metadata?.grantTypes === "string") {
data.metadata.grantTypes = [data.metadata.grantTypes];
}
}
} catch (error: any) {
errorManager(`Error while searching for program by id`, error);
Expand Down

0 comments on commit 3044174

Please sign in to comment.