Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix remove at wrong index #418

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/components/organisms/CreateEventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const CreateEventForm: FC<Props> = ({ address }) => {
},
});

const { remove, append } = useFieldArray({ control, name: "nfts" });
const { fields, remove, append } = useFieldArray({ control, name: "nfts" });

const { gasFee } = useCalcMtxGasFee(watch("mintLimit"));

Expand Down Expand Up @@ -477,6 +477,7 @@ const CreateEventForm: FC<Props> = ({ address }) => {
<NFTAttributesForm
control={control}
nfts={watch("nfts")}
fields={fields}
append={append}
remove={remove}
/>
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/components/organisms/NFTAttributesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Text,
} from "@chakra-ui/react";
import { FC } from "react";
import { Controller, Control, UseFieldArrayRemove } from "react-hook-form";
import { Controller, Control, FieldArray, UseFieldArrayRemove } from "react-hook-form";
import { useLocale } from "../../hooks/useLocale";
import ErrorMessage from "../atoms/form/ErrorMessage";
import ImageSelectorWithPreview from "../ImageSelectorWithPreview";
Expand All @@ -24,11 +24,12 @@ import ordinal from "ordinal";
type Props = {
control: Control<any, any>;
nfts: NFT.NFTImage[];
fields: FieldArray<NFT.NFTImage[]>;
append: (v: any) => void;
remove: UseFieldArrayRemove;
};

const NFTAttributesForm: FC<Props> = ({ control, nfts, append, remove }) => {
const NFTAttributesForm: FC<Props> = ({ control, nfts, fields, append, remove }) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react-hook-formの使い方が少し違っているようでした。
もう少し修正する必要がありそうです

const { t, locale } = useLocale();

const validateUniqRequiredParticipateCount = (v: number) => {
Expand Down Expand Up @@ -56,9 +57,9 @@ const NFTAttributesForm: FC<Props> = ({ control, nfts, append, remove }) => {

return (
<Box>
{nfts.map((nft, index) => (
{fields.map((nft: NFT.NFTImage, index: number) => (
<Flex
key={index}
key={nft.name}
w="full"
flexDirection={{ base: "column", md: "row" }}
mb={10}
Expand Down Expand Up @@ -221,7 +222,10 @@ const NFTAttributesForm: FC<Props> = ({ control, nfts, append, remove }) => {
borderRadius="full"
aria-label=""
icon={<Icon as={CloseIcon} color="mint.primary" />}
onClick={() => remove(index)}
onClick={() => {
console.log(index)
remove(index)
}}
/>
)}
</Flex>
Expand Down