Created
August 19, 2022 10:22
-
-
Save netgfx/27cd1d882b2d827ce93cb91a3dacb7e8 to your computer and use it in GitHub Desktop.
Framer + Airtable calculate total
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getTotal(Component): ComponentType { | |
return (props) => { | |
const [store, setStore] = globalStore() | |
useEffect(() => { | |
var total = 0 | |
var selectedData = [] | |
_.forEach(store.selectedProducts, (item) => { | |
var filteredArray = _.filter( | |
store.airtableData, | |
(product) => product.fields["Short Description"] == item | |
) | |
selectedData.push(filteredArray) | |
}) | |
selectedData = _.flatten(selectedData) | |
for (var i = 0; i < selectedData.length; i++) { | |
total += selectedData[i]["fields"]["Total"] | |
} | |
setStore({ total: total }) | |
}, [store.selectedProducts]) | |
return <Component {...props} text={`\$${store.total}`} /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment