handle set of requests with Promise.all()
by Yury
HTML
<p>
handle set with requests in Promise.all(); <br> (React example)
</p>
CSS
* {
background: #1e1e1e;
font-family: sans-serif;
color: #c0c0c0;
text-align: center;
}
JavaScript
const createNewProduct = async productValues => {
const result = await createPracticeCatalogItem({
variables: {
input: {
organizationId: currentPracticeId,
name: productValues.name,
masterCatalogItemId: productValues.id,
payInFullPrice: 0,
wholesalePrice: productValues.wholesalePrice,
isSubscriptionEnabled: false,
taxRate: 0,
},
},
})
return result
}
const handleSaveAndExit = async () => {
setIsAddProcessing(true)
const addProductActions = selectedProducts.map(createNewProduct)
const newPracticeProductsResponses = await Promise.all(addProductActions)
setIsAddProcessing(false)
if (newPracticeProductsResponses?.length) {
onClose()
refetchPracticeCatalog && refetchPracticeCatalog()
}
}