fix(striker-ui): let fetch refresh handle remove peers after delete

main
Tsu-ba-me 2 years ago
parent eddb0ea393
commit f2cf39a0dc
  1. 34
      striker-ui/components/StrikerConfig/ConfigPeersForm.tsx

@ -163,26 +163,17 @@ const ConfigPeersForm: FC<ConfigPeerFormProps> = ({
listItems={peerConnections} listItems={peerConnections}
onDelete={() => { onDelete={() => {
const pairs = Object.entries(peerConnections); const pairs = Object.entries(peerConnections);
const { const deleteRequestBody =
body: deleteRequestBody, pairs.reduce<APIDeleteHostConnectionRequestBody>(
post: remainingPeerConnections, (previous, [, { hostUUID, isChecked }]) => {
} = pairs.reduce<{ if (isChecked) {
body: APIDeleteHostConnectionRequestBody; previous.local.push(hostUUID);
post: PeerConnectionList; }
}>(
(previous, [key, value]) => { return previous;
const { hostUUID, isChecked } = value; },
{ local: [] },
if (isChecked) { );
previous.body.local.push(hostUUID);
} else {
previous.post[key] = value;
}
return previous;
},
{ body: { local: [] }, post: {} },
);
const deleteCount = deleteRequestBody.local.length; const deleteCount = deleteRequestBody.local.length;
if (deleteCount > 0) { if (deleteCount > 0) {
@ -192,9 +183,6 @@ const ConfigPeersForm: FC<ConfigPeerFormProps> = ({
onProceedAppend: () => { onProceedAppend: () => {
api api
.delete('/host/connection', { data: deleteRequestBody }) .delete('/host/connection', { data: deleteRequestBody })
.then(() => {
setPeerConnections(remainingPeerConnections);
})
.catch((error) => { .catch((error) => {
const emsg = handleAPIError(error); const emsg = handleAPIError(error);

Loading…
Cancel
Save