From 304417445c30f58becabb88846070b5f253c6465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Magalh=C3=A3es?= Date: Mon, 4 Nov 2024 16:01:29 -0300 Subject: [PATCH] fix: grantType coming as string --- .cursorrules | 37 ++++++++ .../Pages/ProgramRegistry/AddProgram.tsx | 93 +++++++++---------- .../Pages/ProgramRegistry/ManagePrograms.tsx | 64 +++++++------ .../ProgramRegistry/ProgramDetailsDialog.tsx | 18 ++-- .../ProgramRegistry/ProgramsExplorer.tsx | 37 ++++---- 5 files changed, 143 insertions(+), 106 deletions(-) create mode 100644 .cursorrules diff --git a/.cursorrules b/.cursorrules new file mode 100644 index 00000000..b5b3132f --- /dev/null +++ b/.cursorrules @@ -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. diff --git a/components/Pages/ProgramRegistry/AddProgram.tsx b/components/Pages/ProgramRegistry/AddProgram.tsx index 46bcfc84..e314c032 100644 --- a/components/Pages/ProgramRegistry/AddProgram.tsx +++ b/components/Pages/ProgramRegistry/AddProgram.tsx @@ -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 = @@ -184,7 +181,6 @@ export default function AddProgram({ }); const { gap } = useGap(); - const [allCommunities, setAllCommunities] = useState( [] ); @@ -204,7 +200,6 @@ export default function AddProgram({ }; if (allCommunities.length === 0) fetchCommunities(); - }, [allCommunities]); const { @@ -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 || [], @@ -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 = @@ -822,7 +821,7 @@ export default function AddProgram({ {errors.networks?.message}

-
+
@@ -866,7 +865,7 @@ export default function AddProgram({ { - onChangeGeneric(community?.uid, "communityRef") + onChangeGeneric(community?.uid, "communityRef"); }} list={allCommunities} selected={watch("communityRef")} @@ -878,7 +877,7 @@ export default function AddProgram({

{programToEdit && ( -
+
diff --git a/components/Pages/ProgramRegistry/ManagePrograms.tsx b/components/Pages/ProgramRegistry/ManagePrograms.tsx index b31653e5..c3058aaf 100644 --- a/components/Pages/ProgramRegistry/ManagePrograms.tsx +++ b/components/Pages/ProgramRegistry/ManagePrograms.tsx @@ -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"; @@ -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) { @@ -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, diff --git a/components/Pages/ProgramRegistry/ProgramDetailsDialog.tsx b/components/Pages/ProgramRegistry/ProgramDetailsDialog.tsx index d86f3bc7..1e9f9dbc 100644 --- a/components/Pages/ProgramRegistry/ProgramDetailsDialog.tsx +++ b/components/Pages/ProgramRegistry/ProgramDetailsDialog.tsx @@ -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, @@ -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; diff --git a/components/Pages/ProgramRegistry/ProgramsExplorer.tsx b/components/Pages/ProgramRegistry/ProgramsExplorer.tsx index c07e3b87..78fda1be 100644 --- a/components/Pages/ProgramRegistry/ProgramsExplorer.tsx +++ b/components/Pages/ProgramRegistry/ProgramsExplorer.tsx @@ -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"]; @@ -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; }, }); @@ -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);