bundles.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { BlockWrapper } from 'app/components/block-wrapper'
  2. import { NeoButton } from 'app/design/controls';
  3. import { fetcher } from 'app/lib/fetcher';
  4. import { Row } from 'app/design/view';
  5. import { Text } from 'app/design/typography';
  6. import { CardList } from 'app/ui/molecules/page/card'
  7. import { useTranslation } from 'react-i18next'
  8. import { useRouter, redirectTo } from 'app/lib/hooks/router'
  9. function ElementBundle({ data }) {
  10. const { t } = useTranslation()
  11. const router = useRouter();
  12. const handlePurchase = async () => {
  13. const res = await fetcher('/api.php?r=' + data.buttons[0].request_url);
  14. if (res.data.url) {
  15. redirectTo(router, res.data.url);
  16. }
  17. else{
  18. redirectTo(router, '/payment-cart?seller_id=38');
  19. }
  20. }
  21. return (
  22. <CardList className="w-[250px]" padding="p-3 sm:p-2 items-center gap-y-4">
  23. <Text className="font-semibold text-4xl tracking-tight text-secondary-foreground">{data.title}</Text>
  24. <Row><Text className="text-2xl font-semibold text-foreground">{t(data.currency_code)} {data.price}</Text></Row>
  25. <NeoButton style="borderedProminent" width="fill" label={data.buttons[0].title} onPress={handlePurchase} classNames={{ root: 'self-stretch flex-none' }} />
  26. </CardList>
  27. )
  28. }
  29. export default function ElementBundles({ data, blockWrapperProps, url }) {
  30. return (
  31. <BlockWrapper {...blockWrapperProps}>
  32. <Row className=" gap-3 flex-wrap justify-center">
  33. {
  34. data.map((item, index) => {
  35. return <ElementBundle key={item.id || item.name || item.title || index} data={item} />
  36. })
  37. }
  38. </Row>
  39. </BlockWrapper>
  40. );
  41. }