Skip to content

Commit

Permalink
Merge pull request #540 from USEPA/feature/update-client-app-env-setup
Browse files Browse the repository at this point in the history
Feature/update client app env setup
  • Loading branch information
courtneymyers authored Jan 27, 2025
2 parents bff90e1 + 6a80569 commit 4682dea
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 42 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ jobs:
run: |
VITE_SERVER_BASE_PATH="$SERVER_BASE_PATH" \
VITE_CLOUD_SPACE="$CLOUD_SPACE" \
VITE_FORMIO_BASE_URL="$FORMIO_BASE_URL" \
VITE_FORMIO_PROJECT_NAME="$FORMIO_PROJECT_NAME" \
npm run build
rm ../server/app/public/index.html
cd build
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ jobs:
run: |
VITE_SERVER_BASE_PATH="$SERVER_BASE_PATH" \
VITE_CLOUD_SPACE="$CLOUD_SPACE" \
VITE_FORMIO_BASE_URL="$FORMIO_BASE_URL" \
VITE_FORMIO_PROJECT_NAME="$FORMIO_PROJECT_NAME" \
npm run build
rm ../server/app/public/index.html
cd build
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ jobs:
run: |
VITE_SERVER_BASE_PATH="$SERVER_BASE_PATH" \
VITE_CLOUD_SPACE="$CLOUD_SPACE" \
VITE_FORMIO_BASE_URL="$FORMIO_BASE_URL" \
VITE_FORMIO_PROJECT_NAME="$FORMIO_PROJECT_NAME" \
npm run build
rm ../server/app/public/index.html
cd build
Expand Down
6 changes: 0 additions & 6 deletions app/client/.env.example

This file was deleted.

21 changes: 17 additions & 4 deletions app/client/src/components/userDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useEffect } from "react";
import { Link, Outlet, useLocation, useNavigate } from "react-router-dom";
import { Formio } from "@formio/react";
import premium from "@formio/premium/lib/index.js";
import uswds from "@formio/uswds";
import icons from "uswds/img/sprite.svg";
// ---
import { serverUrl, formioBaseUrl, formioProjectUrl } from "@/config";
import { serverUrl } from "@/config";
import {
useHelpdeskAccess,
useConfigQuery,
useConfigData,
useBapSamQuery,
useBapSamData,
} from "@/utilities";
import { Loading } from "@/components/loading";
import { useDialogActions } from "@/contexts/dialog";

Formio.setBaseUrl(formioBaseUrl);
Formio.setProjectUrl(formioProjectUrl);
Formio.use(premium); /* eslint-disable-line react-hooks/rules-of-hooks */
Formio.use(uswds); /* eslint-disable-line react-hooks/rules-of-hooks */

Expand Down Expand Up @@ -61,11 +61,24 @@ export function UserDashboard(props: { email: string }) {
useConfigQuery();
useBapSamQuery();

const configData = useConfigData();
const bapSamData = useBapSamData();

const { displayDialog } = useDialogActions();
const helpdeskAccess = useHelpdeskAccess();

useEffect(() => {
const { formioBaseUrl, formioProjectName } = configData ?? {};

if (formioBaseUrl) {
Formio.setBaseUrl(formioBaseUrl);
}

if (formioBaseUrl && formioProjectName) {
Formio.setProjectUrl(`${formioBaseUrl}/${formioProjectName}`);
}
}, [configData]);

const onSubmissionsPage = pathname === "/";
const onHelpdeskPage = pathname === "/helpdesk";
const onFormPage =
Expand Down Expand Up @@ -93,7 +106,7 @@ export function UserDashboard(props: { email: string }) {
});
}

if (!bapSamData || !email) {
if (!configData || !bapSamData || !email) {
return <Loading />;
}

Expand Down
24 changes: 1 addition & 23 deletions app/client/src/config.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
const {
MODE,
VITE_SERVER_BASE_PATH,
VITE_CLOUD_SPACE,
VITE_FORMIO_BASE_URL,
VITE_FORMIO_PROJECT_NAME,
} = import.meta.env;

if (!VITE_FORMIO_BASE_URL) {
const message = `Required VITE_FORMIO_BASE_URL environment variable not found.`;
throw new Error(message);
}

if (!VITE_FORMIO_PROJECT_NAME) {
const message = `Required VITE_FORMIO_PROJECT_NAME environment variable not found.`;
throw new Error(message);
}
const { MODE, VITE_SERVER_BASE_PATH, VITE_CLOUD_SPACE } = import.meta.env;

// allows the app to be accessed from a sub directory of a server (e.g. /csb)
export const serverBasePath =
Expand All @@ -25,12 +9,6 @@ export const serverUrl = window.location.origin + serverBasePath;
export const cloudSpace =
MODE === "development" ? "dev" : VITE_CLOUD_SPACE || "";

export const formioBaseUrl = VITE_FORMIO_BASE_URL;

const formioProjectName = VITE_FORMIO_PROJECT_NAME;

export const formioProjectUrl = `${formioBaseUrl}/${formioProjectName}`;

export const messages = {
genericError: "The application has encountered an unknown error.",
authError: "Authentication error. Please log in again or contact support.",
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type UserData = {
};

export type ConfigData = {
formioBaseUrl: string;
formioProjectName: string;
rebateYear: RebateYear;
submissionPeriodOpen: {
2022: { frf: boolean; prf: boolean; crf: boolean };
Expand Down
6 changes: 5 additions & 1 deletion app/server/app/config/formio.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const {
FORMIO_API_KEY,
} = process.env;

const formioProjectUrl = `${FORMIO_BASE_URL}/${FORMIO_PROJECT_NAME}`;
const formioBaseUrl = FORMIO_BASE_URL;
const formioProjectName = FORMIO_PROJECT_NAME;
const formioProjectUrl = `${formioBaseUrl}/${FORMIO_PROJECT_NAME}`;

/**
* Stores form url for each form by rebate year.
Expand Down Expand Up @@ -166,6 +168,8 @@ const formioNoUserAccess = {

module.exports = {
axiosFormio,
formioBaseUrl,
formioProjectName,
formioProjectUrl,
formUrl,
formIntroSubstring,
Expand Down
8 changes: 7 additions & 1 deletion app/server/app/routes/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const express = require("express");
// ---
const { submissionPeriodOpen } = require("../config/formio");
const {
formioBaseUrl,
formioProjectName,
submissionPeriodOpen,
} = require("../config/formio");
const { ensureAuthenticated } = require("../middleware");

const { CSB_REBATE_YEAR } = process.env;
Expand All @@ -16,6 +20,8 @@ router.get("/", (_req, res) => {
const year = date.getFullYear().toString();

return res.json({
formioBaseUrl,
formioProjectName,
rebateYear: CSB_REBATE_YEAR || year,
submissionPeriodOpen,
});
Expand Down
10 changes: 9 additions & 1 deletion docs/csb-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,20 @@
"parameters": [],
"responses": {
"200": {
"description": "Open enrollment status (true/false) for each form, by rebate year.",
"description": "Formio base URL and project name, CSB rebate year and open enrollment status.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"formioBaseUrl": {
"type": "string",
"example": "https://api.form.io"
},
"formioProjectName": {
"type": "string",
"example": "forms"
},
"rebateYear": {
"schema": {
"type": "string",
Expand Down

0 comments on commit 4682dea

Please sign in to comment.