From dd06acadfd48fd12bd15720682a8352b72e03908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dro=C5=84?= Date: Wed, 27 Sep 2023 15:01:21 +0200 Subject: [PATCH] Fix editing attribute values on new attribute creation (#4266) * Fix editing/deleting attribute value when creating new dropdown attribute * Add changeset * Fix ternary as well --- .changeset/tough-badgers-stare.md | 5 +++++ .../views/AttributeCreate/AttributeCreate.tsx | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 .changeset/tough-badgers-stare.md diff --git a/.changeset/tough-badgers-stare.md b/.changeset/tough-badgers-stare.md new file mode 100644 index 00000000000..dd072a1b663 --- /dev/null +++ b/.changeset/tough-badgers-stare.md @@ -0,0 +1,5 @@ +--- +"saleor-dashboard": patch +--- + +Fix editing/deleting attribute values when creating new dropdown attribute diff --git a/src/attributes/views/AttributeCreate/AttributeCreate.tsx b/src/attributes/views/AttributeCreate/AttributeCreate.tsx index c27d74ce123..86c7223cf4d 100644 --- a/src/attributes/views/AttributeCreate/AttributeCreate.tsx +++ b/src/attributes/views/AttributeCreate/AttributeCreate.tsx @@ -96,7 +96,7 @@ const AttributeDetails: React.FC = ({ params }) => { const [updateMetadata] = useUpdateMetadataMutation({}); const [updatePrivateMetadata] = useUpdatePrivateMetadataMutation({}); - const id = params.id + const id: number | undefined = params.id ? parseInt(params.id, 10) + pageInfo.startCursor : undefined; @@ -108,7 +108,7 @@ const AttributeDetails: React.FC = ({ params }) => { React.useEffect(() => setValueErrors([]), [params.action]); const handleValueDelete = () => { - if (id) { + if (id !== undefined) { const newValues = remove(values[id], values, areValuesEqual); setValues(newValues); } @@ -119,7 +119,7 @@ const AttributeDetails: React.FC = ({ params }) => { if (isSelected(input, values, areValuesEqual)) { setValueErrors([attributeValueAlreadyExistsError]); } else { - if (id) { + if (id !== undefined) { setValues(updateAtIndex(input, values, id)); } closeModal(); @@ -254,14 +254,16 @@ const AttributeDetails: React.FC = ({ params }) => {