From b63c0af77ffaa691016d7dd5c27773d3b860e42d Mon Sep 17 00:00:00 2001 From: ajnart Date: Mon, 3 Jul 2023 21:20:04 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20delete=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Config/Integration/IntegrationModal.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/Config/Integration/IntegrationModal.tsx b/src/components/Config/Integration/IntegrationModal.tsx index af3d1cd8a..5d83b54fe 100644 --- a/src/components/Config/Integration/IntegrationModal.tsx +++ b/src/components/Config/Integration/IntegrationModal.tsx @@ -45,6 +45,7 @@ import { import { useQueryClient } from '@tanstack/react-query'; import { getQueryKey } from '@trpc/react-query'; import { getCookie, setCookie } from 'cookies-next'; +import { produce } from 'immer'; import Link from 'next/link'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -209,13 +210,15 @@ function IntegrationDisplay({ variant="light" color="red" onClick={() => { - if (!integration.type) return null; - // Pop integration from the integrations array - const newIntegrations = integrations; - newIntegrations[integration.type].filter( - (item) => item.id !== integration.id + // Use produce to create a new object with the integration removed + setIntegrations( + produce(integrations, (draft) => { + draft[integration.type!].splice(integrationIdx, 1); + // Remove the type if there are no integrations left + if (draft[integration.type!].length === 0) + delete draft[integration.type!]; + }) ); - setIntegrations(newIntegrations); }} > {t('common:delete')}