Skip to content

Commit

Permalink
migrate app setting to setting json
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCallaghan committed Aug 17, 2021
1 parent fe9d8c9 commit 1ecf2eb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
REACT_APP_API_URL=http://localhost:5000
REACT_APP_RECAPTCHA_SITEKEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
REACT_APP_SHOW_RQ_TOOLS=true
3 changes: 1 addition & 2 deletions src/getAppSetting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export function getAppSetting(key) {
if (window._env_ && window?._env_[key]) {
return window._env_[key];
}
// get the setting from the local settingJSON file
console.log('SETTING', { [key]: settingsJson[key] });
// get the setting from the local settingJSON filew
return settingsJson[key];
}
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { QuestionsProvider } from './contexts/questions';
import { ResponsesProvider } from './contexts/responses';
import { SessionProvider } from './contexts/session';
import AuthProvider from './contexts/auth';
import { getAppSetting } from './getAppSetting';

// .env.development Allows you to hide devtools
const showRQTools = process.env.REACT_APP_SHOW_RQ_TOOLS === 'true';
const showRQTools = getAppSetting('REACT_APP_SHOW_RQ_TOOLS');

ReactDOM.render(
<React.StrictMode>
Expand Down
11 changes: 5 additions & 6 deletions src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import TextInput from '../components/TextInput';
import Wrapper from '../components/Wrapper';
import { loginSchema } from '../helpers/validationSchemas';
import { useAuth } from '../hooks/auth/useAuth';
import { getAppSetting } from '../getAppSetting';

const useStyles = makeStyles(() =>
createStyles({
Expand All @@ -31,7 +32,9 @@ const useStyles = makeStyles(() =>
// LoginPage Component
const LoginPage: React.FC = () => {
const classes = useStyles();
const TEST_RECAPTCHA_KEY = '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'; // Will fall back to test key in CI when .env is
const REACT_APP_RECAPTCHA_SITEKEY = getAppSetting(
'REACT_APP_RECAPTCHA_SITEKEY'
); // Will fall back to test key in CI when not present on the window

const [isVerified, setIsVerified] = useState<boolean>(false);

Expand Down Expand Up @@ -110,11 +113,7 @@ const LoginPage: React.FC = () => {

<Box py={2} className={classes.recaptchaContainer}>
<ReCAPTCHA
sitekey={`${
process.env.REACT_APP_RECAPTCHA_SITEKEY
? process.env.REACT_APP_RECAPTCHA_SITEKEY
: TEST_RECAPTCHA_KEY
}`}
sitekey={REACT_APP_RECAPTCHA_SITEKEY}
onChange={onChange}
/>
</Box>
Expand Down
5 changes: 3 additions & 2 deletions src/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"TEST_SETTING": "Hello",
"REACT_APP_API_URL": "http://localhost:5000"
"REACT_APP_API_URL": "http://localhost:5000",
"REACT_APP_RECAPTCHA_SITEKEY": "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI",
"REACT_APP_SHOW_RQ_TOOLS": true
}

3 comments on commit 1ecf2eb

@rodriguesk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won’t work. Have to have it also in .env.development for the settings to properly get into the header

@rodriguesk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don’t change .env.development
We will handle that in a separate ticket

@rodriguesk
Copy link
Member

@rodriguesk rodriguesk commented on 1ecf2eb Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just have the .env.develop file be blank if that’s what you want. The .env.develop file have dummy info in it. It has to exist or the dev ops code breaks.

Please sign in to comment.