diff --git a/.env b/.env index 0ddd77d..83602a3 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -REACT_APP_API_URL = https://api.footlight.io/calendars/ \ No newline at end of file +REACT_APP_API_URL = https://api.footlight.io/ \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..6604c72 --- /dev/null +++ b/.env.production @@ -0,0 +1,2 @@ +REACT_APP_ENVIRONMENT = PRODUCTION +REACT_APP_API_URL = https://api.footlight.io/ diff --git a/.env.staging b/.env.staging new file mode 100644 index 0000000..5c14938 --- /dev/null +++ b/.env.staging @@ -0,0 +1,2 @@ +REACT_APP_ENVIRONMENT = STAGING +REACT_APP_API_URL = https://staging.api.footlight.io/ diff --git a/.github/workflows/build-production-deploy-s3.yml b/.github/workflows/build-production-deploy-s3.yml index 2770b7e..28b43bb 100644 --- a/.github/workflows/build-production-deploy-s3.yml +++ b/.github/workflows/build-production-deploy-s3.yml @@ -16,5 +16,5 @@ jobs: steps: - uses: actions/checkout@v2 - run: npm install - - run: npm run build + - run: npm run build:production - run: aws s3 sync ./build s3://${{env.WEBHOSTING_BUCKET_NAME}}/ --acl public-read --delete --cache-control max-age=3600 diff --git a/.github/workflows/build-staging-deploy-s3.yml b/.github/workflows/build-staging-deploy-s3.yml index b6eea45..1defddb 100644 --- a/.github/workflows/build-staging-deploy-s3.yml +++ b/.github/workflows/build-staging-deploy-s3.yml @@ -16,5 +16,5 @@ jobs: steps: - uses: actions/checkout@v2 - run: npm install - - run: npm run build + - run: npm run build:staging - run: aws s3 sync ./build s3://${{env.WEBHOSTING_BUCKET_NAME}}/ --acl public-read --delete --cache-control max-age=3600 diff --git a/package.json b/package.json index 0084c42..4bd5c64 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "dayjs": "^1.11.10", + "env-cmd": "^10.1.0", "i18next": "^23.7.11", "react": "^18.2.0", "react-calendar": "^4.7.0", @@ -21,7 +22,10 @@ }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build", + "start:staging": "env-cmd -f .env.staging react-scripts start", + "start:production": "env-cmd -f .env.production react-scripts start", + "build:staging": "env-cmd -f .env.staging react-scripts build", + "build:production": "env-cmd -f .env.production react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject", "lint": "eslint .", @@ -35,6 +39,9 @@ "react-app/jest" ] }, + "engines": { + "node": "^14.17.0" + }, "browserslist": { "production": [ ">0.2%", diff --git a/src/components/card/Card.jsx b/src/components/card/Card.jsx index 9a7fc75..648eda9 100644 --- a/src/components/card/Card.jsx +++ b/src/components/card/Card.jsx @@ -6,16 +6,12 @@ import './card.css'; import { redirectionHandler } from '../../utils/redirectionHandler'; import WidgetContext from '../../context/WidgetContext'; -const Card = ({ id, slug, name, place, image, startDate, endDate }) => { +const Card = ({ id, name, place, image, startDate, endDate }) => { const [imgError, setImgError] = useState(false); const { widgetProps } = useContext(WidgetContext); - const { eventUrl, locale } = widgetProps; + const { calendar } = widgetProps; - let url = eventUrl.replace('${locale}', locale).replace('${eventId}', id); - - if (url.includes('${eventName}')) { - url = url.replace('${eventName}', slug); - } + let redirectionUrl = `${process.env.REACT_APP_API_URL}resource/${id}?calendar=${calendar}`; return (
  • { onClick={(e) => { e.preventDefault(); redirectionHandler({ - url, + url: redirectionUrl, }); }} > diff --git a/src/components/footer/Footer.jsx b/src/components/footer/Footer.jsx index 386c4ba..edf62cf 100644 --- a/src/components/footer/Footer.jsx +++ b/src/components/footer/Footer.jsx @@ -6,30 +6,14 @@ import { redirectionHandler } from '../../utils/redirectionHandler'; const Footer = () => { const { t } = useTranslation(); - const { widgetProps, searchKeyWord, startDateSpan, endDateSpan, totalCount } = - useContext(WidgetContext); + const { widgetProps, totalCount } = useContext(WidgetContext); - const { searchEventsUrl, locale, calendarName } = widgetProps; + const { calendar, calendarName } = widgetProps; + let redirectionUrl = `${process.env.REACT_APP_API_URL}calendars/${calendar}/events/redirect`; const submitHandler = (event) => { event.preventDefault(); - const searchParams = new URLSearchParams(); - - searchParams.append('limit', 100); - if (searchKeyWord !== '' && searchKeyWord) { - widgetProps?.calendar == 'signe-laval' - ? searchParams.append('q', searchKeyWord) - : searchParams.append('query', searchKeyWord); - } - if (startDateSpan) { - searchParams.append('start-date-range', startDateSpan); - } - if (endDateSpan) { - searchParams.append('end-date-range', endDateSpan); - } - - let url = searchEventsUrl.replace('${locale}', locale).trim() + '?' + searchParams.toString(); - redirectionHandler({ url: url }); + redirectionHandler({ url: redirectionUrl }); }; return ( diff --git a/src/utils/generateUrl.js b/src/utils/generateUrl.js index 0ba684b..86cdd44 100644 --- a/src/utils/generateUrl.js +++ b/src/utils/generateUrl.js @@ -1,6 +1,6 @@ /* eslint-disable no-undef */ export const generateUrl = (urlComponents) => { - const baseUrl = process.env.REACT_APP_API_URL; + const baseUrl = process.env.REACT_APP_API_URL + 'calendars/'; const calendar = urlComponents.calendar; const searchEntityType = urlComponents?.searchEntityType; const limit = urlComponents?.limit || 10;