Skip to content

Commit

Permalink
Merge pull request #99 from AppQuality/develop
Browse files Browse the repository at this point in the history
Release 2023-12-11
  • Loading branch information
d-beezee authored Dec 11, 2023
2 parents 42dd4e7 + 462240a commit 1f91807
Show file tree
Hide file tree
Showing 40 changed files with 1,029 additions and 622 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
REACT_APP_API_URL=https://dev.tryber.me/api
REACT_APP_POST_JOTFORM=https://raeo20bhid.execute-api.eu-west-1.amazonaws.com/prod/jotform
REACT_APP_GTM_ID=
REACT_APP_GTM_ID=GTM-K55XC7S
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
REACT_APP_API_URL=/api
REACT_APP_POST_JOTFORM=https://raeo20bhid.execute-api.eu-west-1.amazonaws.com/prod/jotform
REACT_APP_GTM_ID=GTM-TDTZDXJ
REACT_APP_GTM_ID=GTM-K55XC7S
20 changes: 20 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Run tests"
on:
pull_request:
workflow_dispatch:

jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "Install Node"
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install dependencies
run: |
echo //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} > .npmrc
yarn
- name: "Run Test"
run: yarn test:e2e
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
# be deployed to ECS.
docker build \
--build-arg NPM_TOKEN=${{ secrets.NPM_TOKEN }} \
--build-arg SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ generate-devel-token.json

.idea/

generate-devel-token-*
generate-devel-token-*
# Sentry Config File
.sentryclirc
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM node:16.19-alpine3.17 as base

COPY package.json ./
COPY yarn.lock ./
ARG SENTRY_AUTH_TOKEN
ARG NPM_TOKEN
RUN echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
RUN ["yarn", "install", "--frozen-lockfile", "--ignore-scripts"]
Expand All @@ -10,6 +11,7 @@ RUN rm -f .npmrc
COPY . .

RUN ["yarn", "build"]
RUN ["yarn", "sentry:sourcemaps"]


FROM alpine:3.14 as web
Expand Down
28 changes: 28 additions & 0 deletions cypress/e2e/Ux-Dashboard/04-new-empty-dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ describe("Main page", () => {
fixture: "campaigns/id/ux/_get/response/404",
}
).as("getUx");
cy.intercept(
"GET",
`${Cypress.env("REACT_APP_API_URL")}/campaigns/4904/clusters`,
{
statusCode: 200,
fixture: "campaigns/id/clusters/_get/response_200_items",
}
).as("getClusters");
cy.visit(
`${Cypress.env("CAMPAINGS_PAGE")}/4904${Cypress.env(
"UX_DASHBOARD_PAGE"
Expand Down Expand Up @@ -64,4 +72,24 @@ describe("Main page", () => {
cy.dataQa("question-0").should("be.visible");
cy.dataQa("question-", { startsWith: true }).should("have.length", 1);
});
it("should alert the user who try to save a new insight if the insight could not be saved (for absent mandatory fields in the main form)", function () {
const spy = cy.spy();
cy.intercept(
"PATCH",
`${Cypress.env("REACT_APP_API_URL")}/campaigns/4904/ux`,
spy
).as("patchUx");
cy.dataQa("add-new-insight").click();

cy.get("input[name='insights[0].title']").type("test");
cy.get("textarea[name='insights[0].description']").type("test");

cy.dataQa("severity-select").click();
cy.get("#react-select-5-option-0").click();
cy.dataQa("cluster-select").click();
cy.get("#react-select-7-option-0").click();
cy.get('[data-qa="save-insight"]').click({ force: true });
cy.wait(500).then(() => expect(spy).not.to.have.been.called);
cy.get(".toastr-warning").should("be.visible");
});
});
3 changes: 2 additions & 1 deletion deployment/after-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ services:
- '80:80'
environment:
PORT: 80
REACT_APP_ENV: $ENVIRONMENT
REACT_APP_ENVIRONMENT: $ENVIRONMENT
REACT_APP_VERSION: ${DOCKER_IMAGE}
logging:
driver: awslogs
options:
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"@analytics/google-tag-manager": "^0.5.3",
"@appquality/appquality-design-system": "^1.0.49",
"@appquality/craft-blocks": "^0.1.27",
"@appquality/stream-player": "^1.0.4",
"@appquality/stream-player": "^1.0.5",
"@craco/craco": "^6.4.3",
"@craftjs/core": "^0.2.0-beta.5",
"@reduxjs/toolkit": "^1.8.3",
"@sentry/cli": "^2.23.0",
"@sentry/react": "^7.84.0",
"@silevis/reactgrid": "^4.0.4",
"analytics": "^0.8.1",
"husky": "^7.0.4",
Expand All @@ -25,6 +27,7 @@
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^17.0.2",
"react-gtm-module": "^2.0.11",
"react-intersection-observer": "^9.5.2",
"react-redux": "^7.2.6",
"react-router-dom": "^5.2.0",
Expand Down Expand Up @@ -71,7 +74,8 @@
"cy:open": "cypress open --e2e --browser chrome",
"prettier": "npx prettier --write 'src/**/*.{js,jsx,ts,tsx,json,css,scss,md}'",
"translate": "i18next-scanner",
"generate-api": ". ./.env.development; API_URL=$REACT_APP_API_URL/reference/ npx @rtk-query/codegen-openapi src/services/tryberApi/config.ts"
"generate-api": ". ./.env.development; API_URL=$REACT_APP_API_URL/reference/ npx @rtk-query/codegen-openapi src/services/tryberApi/config.ts",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org appquality-srl --project tryber-backoffice ./build && sentry-cli sourcemaps upload --org appquality-srl --project tryber-backoffice ./build"
},
"browserslist": {
"production": [
Expand All @@ -95,6 +99,7 @@
"@types/qs": "^6.9.7",
"@types/react-beautiful-dnd": "^13.1.4",
"@types/react-dom": "^17.0.11",
"@types/react-gtm-module": "^2.0.3",
"@types/react-router-dom": "^5.3.3",
"@types/react-transition-group": "^4.4.4",
"@types/styled-components": "^5.1.23",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<script
type="text/javascript"
src="%PUBLIC_URL%/static/env-config.js"
src="%PUBLIC_URL%/static/env-config.js?v=0.1.0"
></script>
<title>Backoffice &lt; UNGUESS</title>
</head>
Expand Down
3 changes: 2 additions & 1 deletion public/static/env-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
window.react_env = {
REACT_APP_ENV: "local",
REACT_APP_ENVIRONMENT: "local",
REACT_APP_VERSION: "local",
};
127 changes: 73 additions & 54 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
GlobalStyle,
} from "@appquality/appquality-design-system";
import { Provider } from "react-redux";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import { BrowserRouter, Route, Router, Switch } from "react-router-dom";
import * as Sentry from "@sentry/react";
import { createBrowserHistory } from "history";
import BugsList from "src/pages/BugsList";
import CampaignPreselection from "src/pages/campaigns/preselectionForm";
import AdminPayments from "src/pages/Payments";
Expand All @@ -24,62 +26,79 @@ import AgreementsList from "./pages/agreements/list";
import SingleAgreementEdit from "./pages/agreements/view-edit";
import SingleAgreementNew from "./pages/agreements/new";
import UxDashboard from "./pages/UxDashboard";
import SentryWrapper from "./features/SentryWrapper";

const SentryRoute = Sentry.withSentryRouting(Route);
const history = createBrowserHistory();

function App() {
return (
<Provider store={setupStore()}>
<ThemeProvider theme={aqBootstrapTheme}>
<GlobalStyle />
<SiteWideMessages />
<BrowserRouter>
<Switch>
<Route
path={`/backoffice/campaigns/:id/bugs`}
component={BugsList}
/>
<Route
path={`/backoffice/campaigns/:id/prospect`}
component={Prospect}
/>
<Route path={`/backoffice/new`} component={Create} />
<Route path="/backoffice/payments" component={AdminPayments} />
<Route path="/backoffice/jotform" component={Jotform} />
<Route
path="/backoffice/campaigns/preselection-forms/new"
component={CampaignPreselection}
/>
<Route
path="/backoffice/campaigns/preselection-forms/:id"
component={CampaignPreselection}
/>
<Route
path="/backoffice/campaigns/preselection-forms"
component={CampaignPreselectionList}
/>
<Route
path="/backoffice/campaigns/:id/selection"
component={SelectionPage}
/>
<Route
path="/backoffice/campaigns/:id/ux-dashboard"
component={UxDashboard}
/>
<Route path="/backoffice/campaigns" component={Campaigns} />
<Route
path="/backoffice/agreements/new"
component={SingleAgreementNew}
/>
<Route
path="/backoffice/agreements/:id"
component={SingleAgreementEdit}
/>
<Route path="/backoffice/agreements" component={AgreementsList} />
<Route path={`/backoffice/:id`} component={Update} />
<Route path={`/backoffice`} component={List} />
</Switch>
</BrowserRouter>
</ThemeProvider>
</Provider>
<SentryWrapper history={history}>
<Provider store={setupStore()}>
<ThemeProvider theme={aqBootstrapTheme}>
<GlobalStyle />
<SiteWideMessages />
<BrowserRouter>
<Router history={history}>
<Switch>
<SentryRoute
path={`/backoffice/campaigns/:id/bugs`}
component={BugsList}
/>
<SentryRoute
path={`/backoffice/campaigns/:id/prospect`}
component={Prospect}
/>
<SentryRoute path={`/backoffice/new`} component={Create} />
<SentryRoute
path="/backoffice/payments"
component={AdminPayments}
/>
<SentryRoute path="/backoffice/jotform" component={Jotform} />
<SentryRoute
path="/backoffice/campaigns/preselection-forms/new"
component={CampaignPreselection}
/>
<SentryRoute
path="/backoffice/campaigns/preselection-forms/:id"
component={CampaignPreselection}
/>
<SentryRoute
path="/backoffice/campaigns/preselection-forms"
component={CampaignPreselectionList}
/>
<SentryRoute
path="/backoffice/campaigns/:id/selection"
component={SelectionPage}
/>
<SentryRoute
path="/backoffice/campaigns/:id/ux-dashboard"
component={UxDashboard}
/>
<SentryRoute
path="/backoffice/campaigns"
component={Campaigns}
/>
<SentryRoute
path="/backoffice/agreements/new"
component={SingleAgreementNew}
/>
<SentryRoute
path="/backoffice/agreements/:id"
component={SingleAgreementEdit}
/>
<SentryRoute
path="/backoffice/agreements"
component={AgreementsList}
/>
<SentryRoute path={`/backoffice/:id`} component={Update} />
<SentryRoute path={`/backoffice`} component={List} />
</Switch>
</Router>
</BrowserRouter>
</ThemeProvider>
</Provider>
</SentryWrapper>
);
}

Expand Down
38 changes: 38 additions & 0 deletions src/features/PageTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from "react";
import { useGetUsersMeQuery } from "src/services/tryberApi";
import TagManager from "react-gtm-module";
import * as Sentry from "@sentry/react";

export const PageTemplate = ({ children }: { children: React.ReactNode }) => {
const {
data: user,
error,
isLoading,
} = useGetUsersMeQuery({
fields: "id,email,username,wp_user_id,role",
});
if (isLoading) {
return <div>Loading...</div>;
}
TagManager.dataLayer({
dataLayer: {
event: "ApiLoaded",
},
});
Sentry.setUser({
id: user?.id ?? 0,
email: user?.email ?? "unknown",
username: user?.username ?? "unknown",
wp_user_id: user?.wp_user_id ?? 0,
role: user?.role ?? "unknown",
});
if (error) {
if ("status" in error && error.status === 403) {
return <div>You are not logged in. Please log in to continue.</div>;
} else {
if ("message" in error) alert(error.message);
}
return null;
}
return <>{children}</>;
};
41 changes: 41 additions & 0 deletions src/features/SentryWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as Sentry from "@sentry/react";
import isStagingEnvironment from "./isStagingEnvironment";
import { RouterHistory } from "@sentry/react/types/reactrouter";

const SentryWrapper = ({
children,
history,
}: {
children: React.ReactNode;
history: RouterHistory;
}) => {
if (process.env.NODE_ENV !== "test") {
Sentry.init({
dsn: "https://[email protected]/4506320026664960",
integrations: [
new Sentry.BrowserTracing({
routingInstrumentation: Sentry.reactRouterV5Instrumentation(history),
}),
],
environment: react_env.REACT_APP_ENVIRONMENT,
// trace all staging and locale traces and 70% of production traces
tracesSampleRate: isStagingEnvironment() ? 1.0 : 0.7,
// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
tracePropagationTargets: [
"localhost",
/^https:\/\/dev\.tryber\.me\/api/,
/^https:\/\/tryber\.me\/api/,
],
release: react_env.REACT_APP_VERSION,
// Capture Replay for 10% of all sessions,
// plus for 100% of sessions with an error
// do not capture for staging and locale
replaysSessionSampleRate: isStagingEnvironment() ? 0.0 : 0.1,
replaysOnErrorSampleRate: isStagingEnvironment() ? 0.0 : 1.0,
});
}

return <>{children}</>;
};

export default SentryWrapper;
Loading

0 comments on commit 1f91807

Please sign in to comment.