, priceString].join('');\n case Currency.VND:\n return [priceString, 'VND'].join(' ');\n case Currency.YEN:\n return ['¥', priceString].join('');\n case Currency.SUSD:\n return ['S
, priceString].join('');\n }\n};\n\nexport const getDiscountMessage = (\n country: Country,\n currency: Currency,\n discountedPrice: number\n) =\u003E {\n const formattedPrice = formatPriceByCurrency(discountedPrice, currency);\n\n switch (country) {\n case Country.VIETNAM:\n return `The price has been discounted by ${formattedPrice} because you come from Vietnam.`;\n case Country.JAPAN:\n return `We have discounted the price by ${formattedPrice} thanks to the support from Japan's government.`;\n default:\n return `It's lucky that you come from ${country}, because we're running a program that discounts the price by ${discountedPrice}.`;\n }\n};\n","id":"4a18c795-6be1-42f5-8216-c7c6cdce4865","is_binary":false,"title":"price.ts","sha":null,"inserted_at":"2022-11-17T07:21:15","updated_at":"2024-06-01T01:19:29","upload_id":null,"shortid":"q6Om3","source_id":"4af8f1b4-4611-46ff-9d67-6fce2b9a86ab","directory_shortid":"gL4P9"},{"code":"import React from 'react';\r\n\r\nimport { getDiscountMessage, formatPriceByCurrency } from '..\u002Fservices\u002Fprice';\r\nimport { Country, Currency } from '..\u002Ftypes';\r\n\r\nimport styles from '.\u002FPricingCardBody.module.css';\r\n\r\ninterface PricingCardBodyProps {\r\n price: number;\r\n currency: Currency;\r\n country?: Country;\r\n}\r\n\r\nconst PricingCardBody: React.FC\u003CPricingCardBodyProps\u003E = ({\r\n price,\r\n currency,\r\n country\r\n}) =\u003E {\r\n const discountedRatio =\r\n country === Country.VIETNAM ? 0.4 : country === Country.JAPAN ? 0.2 : 0;\r\n const isDiscounted = discountedRatio \u003E 0;\r\n const finalPrice = price * (1 - discountedRatio);\r\n const discountedPrice = price - finalPrice;\r\n\r\n return (\r\n \u003Cdiv className={styles.body}\u003E\r\n \u003Ch1\u003E{formatPriceByCurrency(finalPrice, currency)}\u003C\u002Fh1\u003E\r\n {isDiscounted && country && (\r\n \u003Cdiv className={styles.discount}\u003E\r\n {getDiscountMessage(country, currency, discountedPrice)}\r\n \u003C\u002Fdiv\u003E\r\n )}\r\n \u003Cp\u003ELearn the essential skills for modern fullstack app development.\u003C\u002Fp\u003E\r\n \u003Cbutton className={styles.buyButton}\u003EGet started\u003C\u002Fbutton\u003E\r\n \u003C\u002Fdiv\u003E\r\n );\r\n};\r\n\r\nexport default PricingCardBody;\r\n","id":"87bb6145-ba42-44e7-83af-87eec0dff6d6","is_binary":false,"title":"PricingCardBody.tsx","sha":null,"inserted_at":"2022-11-10T14:29:00","updated_at":"2024-06-01T01:20:09","upload_id":null,"shortid":"71EAr","source_id":"4af8f1b4-4611-46ff-9d67-6fce2b9a86ab","directory_shortid":"lVp41"}],"alias":"react-strategy-pattern-problem-h59r02","like_count":0,"always_on":false,"npm_dependencies":{"react":"16.0.0","react-dom":"16.0.0"},"title":"React Strategy Pattern (Problem)","v2":false,"pr_number":null,"inserted_at":"2022-11-10T14:19:25","npm_registries":[],"updated_at":"2024-06-01T01:22:29","id":"h59r02","view_count":296896,"authorization":"read","git":null,"author":{"id":"89be0091-3b9b-4657-aaa5-873c1687cdc0","name":"Will T.","username":"will-t","avatar_url":"https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F24670327?v=4","personal_workspace_id":"81111bd7-0891-4c3b-82b3-deff3f8cf523","subscription_plan":null,"subscription_since":null},"screenshot_url":"https:\u002F\u002Fscreenshots.codesandbox.io\u002Fh59r02\u002F174.png","owned":false,"forked_template":{"id":"a49eb2ed-5233-4480-a2ca-794626c4e1e3","title":"React (TS)","color":"#61DAFB","v2":false,"url":null,"published":false,"icon_url":null,"official":false},"forked_from_sandbox":{"alias":"react-typescript-xlpsg","id":"xlpsg","title":"React Typescript","template":"create-react-app","inserted_at":"2021-04-14T09:12:52","updated_at":"2021-04-14T09:12:52","git":null,"privacy":0,"custom_template":null},"settings":{"ai_consent":null},"forked_template_sandbox":{"alias":"react-ts-react-ts","id":"react-ts","title":"React (TS)","template":"create-react-app","inserted_at":"2018-12-18T10:31:20","updated_at":"2024-08-19T10:30:06","git":null,"privacy":0,"custom_template":{"id":"a49eb2ed-5233-4480-a2ca-794626c4e1e3","title":"React (TS)","color":"#61DAFB","v2":false,"url":null,"published":false,"icon_url":null,"official":false}},"custom_template":null,"preview_secret":null};