diff --git a/gatsby-config.js b/gatsby-config.js index bc37e70..906a952 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -42,7 +42,8 @@ module.exports = { { resolve: 'gatsby-source-filesystem', options: { - path: 'content/', + name: 'content', + path: `${__dirname}/content`, }, }, { diff --git a/netlify/edge-functions/get_country.js b/netlify/edge-functions/get_country.js new file mode 100644 index 0000000..1650d5a --- /dev/null +++ b/netlify/edge-functions/get_country.js @@ -0,0 +1,5 @@ +export default async (req, { geo }) => { + return Response.json({ country: geo?.country?.code }); +}; + +export const config = { path: '/api/get_country' }; diff --git a/package-lock.json b/package-lock.json index 2b59fb4..200b041 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,6 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "reactstrap": "^9.2.0", - "request-ip": "^3.3.0", "sass": "^1.68.0", "styled-components": "^6.0.8", "yup": "^1.3.2" @@ -24044,11 +24043,6 @@ "node": ">=0.10.0" } }, - "node_modules/request-ip": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/request-ip/-/request-ip-3.3.0.tgz", - "integrity": "sha512-cA6Xh6e0fDBBBwH77SLJaJPBmD3nWVAcF9/XAcsrIHdjhFzFiB5aNQFytdjCGPezU3ROwrR11IddKAM08vohxA==" - }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -44695,11 +44689,6 @@ } } }, - "request-ip": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/request-ip/-/request-ip-3.3.0.tgz", - "integrity": "sha512-cA6Xh6e0fDBBBwH77SLJaJPBmD3nWVAcF9/XAcsrIHdjhFzFiB5aNQFytdjCGPezU3ROwrR11IddKAM08vohxA==" - }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", diff --git a/package.json b/package.json index 98ba582..57f3904 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "reactstrap": "^9.2.0", - "request-ip": "^3.3.0", "sass": "^1.68.0", "styled-components": "^6.0.8", "yup": "^1.3.2" diff --git a/src/api/create_order.js b/src/api/create_order.js index bb52d3d..ffbac8f 100644 --- a/src/api/create_order.js +++ b/src/api/create_order.js @@ -81,5 +81,5 @@ export default async function handler(req, res) { } function createOrderId() { - return crypto.randomBytes(16).toString('hex'); + return crypto.randomBytes(8).toString('hex'); } diff --git a/src/api/get_country.js b/src/api/get_country.js deleted file mode 100644 index fab7053..0000000 --- a/src/api/get_country.js +++ /dev/null @@ -1,17 +0,0 @@ -const axios = require('axios'); -const requestIp = require('request-ip'); - -const IP_API_URL = 'http://ip-api.com/json/'; - -export default async function getCountry(req, res) { - const clientIp = requestIp.getClientIp(req); - - try { - const { data } = await axios.get(IP_API_URL + clientIp); - if (data.status === 'fail') throw new Error(data.message); - res.json({ country: data.countryCode }); - } catch (e) { - console.log(e); - res.status(400).json({ error: e.toString() }); - } -} diff --git a/src/pages/confirmation.js b/src/pages/confirmation.js index f6cf26b..cc8c05c 100644 --- a/src/pages/confirmation.js +++ b/src/pages/confirmation.js @@ -12,6 +12,9 @@ export const query = graphql` scholarship_info contact_email confirmation_message + currency { + symbol + } payment_options { bank_transfer mobile_money_transfer @@ -29,15 +32,18 @@ export default function Confirmation({ data }) { contact_email, confirmation_message, payment_options, + currency, } = data.allRetreatsYaml.edges[0].node; const [needScholarship, setNeedScholarship] = useState(false); const [paymentMethod, setPaymentMethod] = useState(); + const [totalPayable, setTotalPayable] = useState(0); useEffect(() => { const params = new URLSearchParams(location.search); setNeedScholarship(params.get('need_scholarship') === 'true'); setPaymentMethod(params.get('payment_method')); - }, [needScholarship, paymentMethod]); + setTotalPayable(parseInt(params.get('total_payable') || 0, 10)); + }, [needScholarship, paymentMethod, totalPayable]); return (
@@ -56,14 +62,22 @@ export default function Confirmation({ data }) { />
)} - {paymentMethod && payment_options[paymentMethod] && ( -
- Payment -
- {payment_options[paymentMethod]} + {!needScholarship && + paymentMethod && + payment_options[paymentMethod] && ( +
+ Payment +
+ {payment_options[paymentMethod]} +
+ {totalPayable > 0 && ( +
+ Total Payable: {totalPayable} + {currency.symbol} +
+ )}
-
- )} + )}
Contact us diff --git a/src/pages/index.js b/src/pages/index.js index 8a8fa78..310b144 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -3,13 +3,31 @@ import PropTypes from 'prop-types'; import { graphql } from 'gatsby'; import { GatsbyImage, getImage } from 'gatsby-plugin-image'; import classnames from 'classnames'; -import marked from '../lib/marked'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; +import axios from 'axios'; +// import requestIp from 'request-ip'; import format from 'date-fns/format'; +import marked from '../lib/marked'; import Nav from '../components/Nav'; import RegistrationForm from '../components/RegistrationForm'; +// @todo may be rename DOMAIN_HOST to BASE_URL + +export async function getServerData() { + try { + const { data } = await axios.get( + process.env.DOMAIN_HOST + '/api/get_country', + ); + return { props: data.country, status: 200 }; + } catch (error) { + console.log(error.toString()); + return { + props: { country: '', status: 200 }, + }; + } +} + // get the latest retreat by sorting latest export const query = graphql` query { @@ -106,7 +124,7 @@ export const query = graphql` } `; -export default function Home({ data }) { +export default function Home({ data, serverData }) { // display the latest retreat const { title, @@ -352,6 +370,7 @@ export default function Home({ data }) { currency={currency} contact_email={contact_email} registration_info={marked(registration.text)} + country={serverData.country} />
@@ -362,6 +381,7 @@ export default function Home({ data }) { Home.propTypes = { data: PropTypes.object, + serverData: PropTypes.object, }; /* eslint-disable */