diff --git a/client/eulaize.js b/client/eulaize.js new file mode 100644 index 000000000..26b972f15 --- /dev/null +++ b/client/eulaize.js @@ -0,0 +1,16 @@ +const fs = require('fs'); + + +const filename = process.argv[2]; + +fs.readFile(filename, 'utf8', (err, data) => { + if (err) { + console.error(`Error reading file ${filename}:`, err); + return; + } + const filteredData = JSON.stringify(data); + console.log('Select the content between the quotes below and paste it into the EULA Content field in the EULA Content table in the database.') + console.log('--------------------------------------------------') + console.log(filteredData); + console.log('--------------------------------------------------') +}); \ No newline at end of file diff --git a/client/package-lock.json b/client/package-lock.json index 1d2c454f9..11952eff4 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -19449,6 +19449,14 @@ "react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0" } }, + "node_modules/react-smooth/node_modules/dom-helpers": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.4.0.tgz", + "integrity": "sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA==", + "dependencies": { + "@babel/runtime": "^7.1.2" + } + }, "node_modules/react-smooth/node_modules/fast-equals": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-5.0.1.tgz", @@ -19457,6 +19465,21 @@ "node": ">=6.0.0" } }, + "node_modules/react-smooth/node_modules/react-transition-group": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-2.9.0.tgz", + "integrity": "sha512-+HzNTCHpeQyl4MJ/bdE0u6XRMe9+XG/+aL4mCxVN4DnPBQ0/5bfHWPDuOZUzYdMj94daZaZdCCc1Dzt9R/xSSg==", + "dependencies": { + "dom-helpers": "^3.4.0", + "loose-envify": "^1.4.0", + "prop-types": "^15.6.2", + "react-lifecycles-compat": "^3.0.4" + }, + "peerDependencies": { + "react": ">=15.0.0", + "react-dom": ">=15.0.0" + } + }, "node_modules/react-sticky": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/react-sticky/-/react-sticky-6.0.3.tgz", @@ -19497,29 +19520,6 @@ "resolved": "https://registry.npmjs.org/style-utils/-/style-utils-0.1.24.tgz", "integrity": "sha512-MVZSKubpU/vIfpmOsi8/0ckWxb0WmGBmyNoEDGWZM9cM8n8sCL6DJftl3lEf8Uy5zKQ9+O1XdJxscWTDosCQpQ==" }, - "node_modules/react-transition-group": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-2.9.0.tgz", - "integrity": "sha512-+HzNTCHpeQyl4MJ/bdE0u6XRMe9+XG/+aL4mCxVN4DnPBQ0/5bfHWPDuOZUzYdMj94daZaZdCCc1Dzt9R/xSSg==", - "dependencies": { - "dom-helpers": "^3.4.0", - "loose-envify": "^1.4.0", - "prop-types": "^15.6.2", - "react-lifecycles-compat": "^3.0.4" - }, - "peerDependencies": { - "react": ">=15.0.0", - "react-dom": ">=15.0.0" - } - }, - "node_modules/react-transition-group/node_modules/dom-helpers": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.4.0.tgz", - "integrity": "sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA==", - "dependencies": { - "@babel/runtime": "^7.1.2" - } - }, "node_modules/react-virtualized": { "version": "9.22.5", "resolved": "https://registry.npmjs.org/react-virtualized/-/react-virtualized-9.22.5.tgz", diff --git a/client/package.json b/client/package.json index c99eda9ef..be72ee257 100644 --- a/client/package.json +++ b/client/package.json @@ -93,6 +93,7 @@ "buildcra": "REACT_APP_GIT_SHA=`git rev-parse --short HEAD` craco build", "test": "cypress open", "eject": "react-scripts eject", + "eulaize": "node eulaize.js", "madge": "madge --image ./madge-graph.svg --extensions js,jsx,ts,tsx --circular ." }, "eslintConfig": { diff --git a/client/src/App/App.jsx b/client/src/App/App.jsx index 9e52ed9ed..caa5b94f2 100644 --- a/client/src/App/App.jsx +++ b/client/src/App/App.jsx @@ -122,7 +122,7 @@ export function App({bodyshop, checkUserSession, currentUser, online, setOnline} /> ); - if (!currentUser.isEulaAccepted) { + if (!currentUser.eulaIsAccepted) { return } diff --git a/client/src/components/eula/eula.component.jsx b/client/src/components/eula/eula.component.jsx index af3bc819e..63337d184 100644 --- a/client/src/components/eula/eula.component.jsx +++ b/client/src/components/eula/eula.component.jsx @@ -1,37 +1,89 @@ -import React, {useState} from "react"; +import React, {useCallback, useEffect, useRef, useState} from "react"; import {Button, Card, Checkbox, Col, Form, Input, Modal, Row, Space} from "antd"; import Markdown from "react-markdown"; +import {createStructuredSelector} from "reselect"; +import {selectCurrentEula, selectCurrentUser} from "../../redux/user/user.selectors"; +import {connect} from "react-redux"; +import {FormDatePicker} from "../form-date-picker/form-date-picker.component"; +import {INSERT_EULA_ACCEPTANCE} from "../../graphql/user.queries"; +import {useMutation} from "@apollo/client"; +import {acceptEula} from "../../redux/user/user.actions"; -const EULA = require('./testData.json').eula; -/** - * Returns the EULA component. - * @returns {Element} - * @constructor - */ +const mapStateToProps = createStructuredSelector({ + currentEula: selectCurrentEula, + currentUser: selectCurrentUser, +}); -//REDUXY THIS -export default function Eula({eulaContentToShow}) { - const [isModalOpen, setIsModalOpen] = useState(true); +const mapDispatchToProps = (dispatch) => ({ + acceptEula: () => dispatch(acceptEula()), +}); - const handleAccept = (values) => { - localStorage.setItem('termsAccepted', 'true'); - setIsModalOpen(false); +export function Eula({currentEula, currentUser, acceptEula}) { + const [formReady, setFormReady] = useState(false); // [formReady, setFormReady + const [hasEverScrolledToBottom, setHasEverScrolledToBottom] = useState(false); + const [insertEulaAcceptance] = useMutation(INSERT_EULA_ACCEPTANCE); + const [form] = Form.useForm(); + const markdownDivRef = useRef(null); - //Insert and Dispatch the action to rechecuk force acceptance. + const handleAccept = async ({acceptTerms, ...formValues}) => { + + const eulaId = currentEula.id; + const useremail = currentUser.email; + + try { + await insertEulaAcceptance({ + variables: { + eulaAcceptance: { + eulaid: eulaId, + useremail, + ...formValues, + date_accepted: new Date(), + } + } + }); + + acceptEula(); + } catch (err) { + // Pop notification with error, pop console + console.error(err); + } +//R + // setIsModalOpen(false); + //Insert and Dispatch the action to recheck force acceptance. }; + const handleScroll = (e) => { + const bottom = e.target.scrollHeight - 100 <= e.target.scrollTop + e.target.clientHeight; + if (bottom && !hasEverScrolledToBottom) { + setHasEverScrolledToBottom(true); + } + }; + + const handleChange = useCallback(() => { + form.validateFields({ + validateOnly: true, + }).then(() => { + setFormReady(hasEverScrolledToBottom); + }).catch(() => { + setFormReady(false); + }); + }, [form, hasEverScrolledToBottom]); + + + useEffect(() => { + handleChange(); + }, [handleChange, hasEverScrolledToBottom, form]); + return ( - <> - - + )} closable={false} > @@ -40,17 +92,20 @@ export default function Eula({eulaContentToShow}) { maxHeight: '50vh', overflowY: 'auto', backgroundColor: 'lightgray', - padding: '0 25px 0 25px' - }}> - + }} onScroll={handleScroll} ref={markdownDivRef}> +
+ +
-
+ @@ -59,7 +114,7 @@ export default function Eula({eulaContentToShow}) { @@ -70,7 +125,7 @@ export default function Eula({eulaContentToShow}) { @@ -79,7 +134,13 @@ export default function Eula({eulaContentToShow}) { @@ -97,28 +158,38 @@ export default function Eula({eulaContentToShow}) { - + + + + + + + + value ? Promise.resolve() : Promise.reject(new Error('You must accept the terms and conditions')), + }, + ]} + > + I accept the terms and conditions - - value ? Promise.resolve() : Promise.reject(new Error('You must accept the terms and conditions')), - }, - ]} - > - I accept the terms and conditions -
+ {!hasEverScrolledToBottom && ( + +

You must scroll to the bottom of the Terms and Conditions before accepting.

+
+ )}
} +export default connect(mapStateToProps, mapDispatchToProps)(Eula); \ No newline at end of file diff --git a/client/src/components/eula/testData.json b/client/src/components/eula/testData.json deleted file mode 100644 index 03827a783..000000000 --- a/client/src/components/eula/testData.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "eula": "# End User License Agreement (EULA)\n## 1. Introduction\n\nThis End User License Agreement (\"EULA\") governs your use of our website and any related services. By using our website, you agree to be bound by the terms of this EULA.\n\n## 2. License Grant\n\nWe grant you a non-exclusive, non-transferable, revocable license to use our website for your personal, non-commercial use.\n\n## 3. Restrictions\n\nYou agree not to:\n\n- Use our website for any illegal or unauthorized purpose\n- Attempt to reverse engineer or otherwise derive the source code of our website\n\n## 4. Termination\n\nWe reserve the right to terminate your license to use our website at any time and for any reason.\n\n## 5. Disclaimer of Warranties\n\nOur website is provided \"as is\" and without any warranty of any kind.\n\n## 6. Limitation of Liability\n\nWe will not be liable for any damages or losses arising from your use of our website.\n\n## 7. Governing Law\n\nThis EULA is governed by the laws of [Your Jurisdiction].\n\n## 8. Changes to this EULA\n\nWe reserve the right to modify this EULA at any time. Your continued use of our website after any such changes constitutes your acceptance of the new EULA.\n\n## 9. Contact Us\n\nIf you have any questions about this EULA, please contact us at [Your Contact Information].\n## 1. Introduction\n\nThis End User License Agreement (\"EULA\") governs your use of our website and any related services. By using our website, you agree to be bound by the terms of this EULA.\n\n## 2. License Grant\n\nWe grant you a non-exclusive, non-transferable, revocable license to use our website for your personal, non-commercial use.\n\n## 3. Restrictions\n\nYou agree not to:\n\n- Use our website for any illegal or unauthorized purpose\n- Attempt to reverse engineer or otherwise derive the source code of our website\n\n## 4. Termination\n\nWe reserve the right to terminate your license to use our website at any time and for any reason.\n\n## 5. Disclaimer of Warranties\n\nOur website is provided \"as is\" and without any warranty of any kind.\n\n## 6. Limitation of Liability\n\nWe will not be liable for any damages or losses arising from your use of our website.\n\n## 7. Governing Law\n\nThis EULA is governed by the laws of [Your Jurisdiction].\n\n## 8. Changes to this EULA\n\nWe reserve the right to modify this EULA at any time. Your continued use of our website after any such changes constitutes your acceptance of the new EULA.\n\n## 9. Contact Us\n\nIf you have any questions about this EULA, please contact us at [Your Contact Information].\n## 1. Introduction\n\nThis End User License Agreement (\"EULA\") governs your use of our website and any related services. By using our website, you agree to be bound by the terms of this EULA.\n\n## 2. License Grant\n\nWe grant you a non-exclusive, non-transferable, revocable license to use our website for your personal, non-commercial use.\n\n## 3. Restrictions\n\nYou agree not to:\n\n- Use our website for any illegal or unauthorized purpose\n- Attempt to reverse engineer or otherwise derive the source code of our website\n\n## 4. Termination\n\nWe reserve the right to terminate your license to use our website at any time and for any reason.\n\n## 5. Disclaimer of Warranties\n\nOur website is provided \"as is\" and without any warranty of any kind.\n\n## 6. Limitation of Liability\n\nWe will not be liable for any damages or losses arising from your use of our website.\n\n## 7. Governing Law\n\nThis EULA is governed by the laws of [Your Jurisdiction].\n\n## 8. Changes to this EULA\n\nWe reserve the right to modify this EULA at any time. Your continued use of our website after any such changes constitutes your acceptance of the new EULA.\n\n## 9. Contact Us\n\nIf you have any questions about this EULA, please contact us at [Your Contact Information]." -} \ No newline at end of file diff --git a/client/src/graphql/user.queries.js b/client/src/graphql/user.queries.js index 09ba53787..d69429ba5 100644 --- a/client/src/graphql/user.queries.js +++ b/client/src/graphql/user.queries.js @@ -31,6 +31,14 @@ export const UPDATE_ASSOCIATION = gql` } `; +export const INSERT_EULA_ACCEPTANCE = gql` + mutation INSERT_EULA_ACCEPTANCE($eulaAcceptance:eula_acceptances_insert_input!) { + insert_eula_acceptances_one(object: $eulaAcceptance){ + id + } + } +`; + export const UPSERT_USER = gql` mutation UPSERT_USER($authEmail: String!, $authToken: String!) { insert_users( diff --git a/client/src/redux/user/user.actions.js b/client/src/redux/user/user.actions.js index f5a9a2d4f..b5c62a73c 100644 --- a/client/src/redux/user/user.actions.js +++ b/client/src/redux/user/user.actions.js @@ -110,8 +110,12 @@ export const setAuthlevel = (authlevel) => ({ payload: authlevel, }); -export const setEulaContentToShow = (eulaContent) => ({ - type: UserActionTypes.SET_EULA_CONTENT, - payload: eulaContent, +export const setCurrentEula = (eula) => ({ + type: UserActionTypes.SET_CURRENT_EULA, + payload: eula, +}); + +export const acceptEula = () => ({ + type: UserActionTypes.EULA_ACCEPTED, }); diff --git a/client/src/redux/user/user.reducer.js b/client/src/redux/user/user.reducer.js index 641d127c2..5a1644f3b 100644 --- a/client/src/redux/user/user.reducer.js +++ b/client/src/redux/user/user.reducer.js @@ -18,7 +18,7 @@ const INITIAL_STATE = { loading: false, }, authLevel: 0, - eulaContentToShow:null + currentEula: null, }; const userReducer = (state = INITIAL_STATE, action) => { @@ -65,11 +65,19 @@ const userReducer = (state = INITIAL_STATE, action) => { loading: false, }, }; + case UserActionTypes.EULA_ACCEPTED: + return { + ...state, + currentUser:{...state.currentUser, eulaIsAccepted: true}, + currentEula: null, + }; case UserActionTypes.SIGN_IN_SUCCESS: + const{ currentEula,...currentUser} = action.payload return { ...state, loginLoading: false, - currentUser: action.payload, + currentUser: currentUser, + currentEula, error: null, }; case UserActionTypes.SIGN_OUT_SUCCESS: diff --git a/client/src/redux/user/user.sagas.js b/client/src/redux/user/user.sagas.js index 867c8e0cb..50201ba5d 100644 --- a/client/src/redux/user/user.sagas.js +++ b/client/src/redux/user/user.sagas.js @@ -97,7 +97,7 @@ export function* isUserAuthenticated() { }, }); - const isEulaAccepted = eulaQuery.data.eulas.length > 0 && eulaQuery.data.eulas[0].eula_acceptances.length > 0; + const eulaIsAccepted = eulaQuery.data.eulas.length > 0 && eulaQuery.data.eulas[0].eula_acceptances.length > 0; yield put( signInSuccess({ @@ -106,7 +106,8 @@ export function* isUserAuthenticated() { displayName: user.displayName, photoURL: user.photoURL, authorized: true, - isEulaAccepted, + eulaIsAccepted, + currentEula: eulaIsAccepted ? null : eulaQuery.data.eulas[0], }) ); } catch (error) { diff --git a/client/src/redux/user/user.selectors.js b/client/src/redux/user/user.selectors.js index c3d0fe572..6e2193a10 100644 --- a/client/src/redux/user/user.selectors.js +++ b/client/src/redux/user/user.selectors.js @@ -37,7 +37,7 @@ export const selectLoginLoading = createSelector( (user) => user.loginLoading ); -export const selectEulaContentToShow = createSelector( +export const selectCurrentEula = createSelector( [selectUser], - (user) => user.eulaContentToShow + (user) => user.currentEula ); diff --git a/client/src/redux/user/user.types.js b/client/src/redux/user/user.types.js index cd4e952cd..0e153b31a 100644 --- a/client/src/redux/user/user.types.js +++ b/client/src/redux/user/user.types.js @@ -32,6 +32,7 @@ const UserActionTypes = { CHECK_ACTION_CODE_START: "CHECK_ACTION_CODE_START", CHECK_ACTION_CODE_SUCCESS: "CHECK_ACTION_CODE_SUCCESS", CHECK_ACTION_CODE_FAILURE: "CHECK_ACTION_CODE_FAILURE", - SET_EULA_CONTENT: "SET_EULA_CONTENT" + SET_CURRENT_EULA: "SET_CURRENT_EULA", + EULA_ACCEPTED : "EULA_ACCEPTED", }; export default UserActionTypes; diff --git a/client/test.md b/client/test.md new file mode 100644 index 000000000..186553d61 --- /dev/null +++ b/client/test.md @@ -0,0 +1,31 @@ +# End User License Agreement (EULA) + +## 1. Introduction + +This End User License Agreement ("EULA") is a legal agreement between you and [Your Company Name] ("Company"). This EULA governs your acquisition and use of our [Software Name] ("Software") directly from [Your Company Name] or indirectly through a [Your Company Name] authorized reseller or distributor. + +By installing and/or using the [Software Name], you are confirming your acceptance of the Software and agreeing to become bound by the terms of this EULA agreement. + +## 2. License + +[Your Company Name] hereby grants you a personal, non-transferable, non-exclusive licence to use the [Software Name] on your devices in accordance with the terms of this EULA agreement. + +## 3. Restrictions + +You are not permitted to: + +- Edit, alter, modify, adapt, translate or otherwise change the whole or any part of the Software nor permit the whole or any part of the Software to be combined with or become incorporated in any other software, nor decompile, disassemble or reverse engineer the Software or attempt to do any such things. + +- Reproduce, copy, distribute, resell or otherwise use the Software for any commercial purpose. + +- Allow any third party to use the Software on behalf of or for the benefit of any third party. + +- Use the Software in any way which breaches any applicable local, national or international law. + +## 4. Termination + +This EULA agreement is effective from the date you first use the Software and shall continue until terminated. You may terminate it at any time upon written notice to [Your Company Name]. + +## 5. Governing Law + +This EULA agreement, and any dispute arising out of or in connection with this EULA agreement, shall be governed by and construed in accordance with the laws of [Your Country]. \ No newline at end of file diff --git a/hasura/metadata/functions.yaml b/hasura/metadata/functions.yaml index 3ef10184a..5dd1b8640 100644 --- a/hasura/metadata/functions.yaml +++ b/hasura/metadata/functions.yaml @@ -1,3 +1,6 @@ +- function: + name: jobs_ar_summary + schema: public - function: name: search_bills schema: public diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index f4e4d99a7..a8e271f93 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -2442,7 +2442,7 @@ _eq: X-Hasura-User-Id columns: - address - - buisness_name + - business_name - date_accepted - eulaid - first_name @@ -2454,7 +2454,7 @@ permission: columns: - address - - buisness_name + - business_name - first_name - last_name - phone_number @@ -2673,6 +2673,9 @@ - table: name: ioevents schema: public +- table: + name: job_ar_schema + schema: public - table: name: job_conversations schema: public @@ -3812,6 +3815,7 @@ - referral_source - referral_source_extra - regie_number + - remove_from_ar - ro_number - scheduled_completion - scheduled_delivery @@ -4093,6 +4097,7 @@ - referral_source - referral_source_extra - regie_number + - remove_from_ar - ro_number - scheduled_completion - scheduled_delivery diff --git a/hasura/migrations/1705712927924_alter_table_public_eula_acceptances_alter_column_buisness_name/down.sql b/hasura/migrations/1705712927924_alter_table_public_eula_acceptances_alter_column_buisness_name/down.sql new file mode 100644 index 000000000..8c4d38542 --- /dev/null +++ b/hasura/migrations/1705712927924_alter_table_public_eula_acceptances_alter_column_buisness_name/down.sql @@ -0,0 +1 @@ +alter table "public"."eula_acceptances" rename column "business_name" to "buisness_name"; diff --git a/hasura/migrations/1705712927924_alter_table_public_eula_acceptances_alter_column_buisness_name/up.sql b/hasura/migrations/1705712927924_alter_table_public_eula_acceptances_alter_column_buisness_name/up.sql new file mode 100644 index 000000000..7dc59b9f6 --- /dev/null +++ b/hasura/migrations/1705712927924_alter_table_public_eula_acceptances_alter_column_buisness_name/up.sql @@ -0,0 +1 @@ +alter table "public"."eula_acceptances" rename column "buisness_name" to "business_name"; diff --git a/hasura/migrations/1705715500461_alter_table_public_eula_acceptances_alter_column_phone_number/down.sql b/hasura/migrations/1705715500461_alter_table_public_eula_acceptances_alter_column_phone_number/down.sql new file mode 100644 index 000000000..08ab66099 --- /dev/null +++ b/hasura/migrations/1705715500461_alter_table_public_eula_acceptances_alter_column_phone_number/down.sql @@ -0,0 +1 @@ +alter table "public"."eula_acceptances" alter column "phone_number" set not null; diff --git a/hasura/migrations/1705715500461_alter_table_public_eula_acceptances_alter_column_phone_number/up.sql b/hasura/migrations/1705715500461_alter_table_public_eula_acceptances_alter_column_phone_number/up.sql new file mode 100644 index 000000000..de5721802 --- /dev/null +++ b/hasura/migrations/1705715500461_alter_table_public_eula_acceptances_alter_column_phone_number/up.sql @@ -0,0 +1 @@ +alter table "public"."eula_acceptances" alter column "phone_number" drop not null; diff --git a/hasura/migrations/1705715523486_alter_table_public_eula_acceptances_alter_column_address/down.sql b/hasura/migrations/1705715523486_alter_table_public_eula_acceptances_alter_column_address/down.sql new file mode 100644 index 000000000..fa66ebd58 --- /dev/null +++ b/hasura/migrations/1705715523486_alter_table_public_eula_acceptances_alter_column_address/down.sql @@ -0,0 +1 @@ +alter table "public"."eula_acceptances" alter column "address" set not null; diff --git a/hasura/migrations/1705715523486_alter_table_public_eula_acceptances_alter_column_address/up.sql b/hasura/migrations/1705715523486_alter_table_public_eula_acceptances_alter_column_address/up.sql new file mode 100644 index 000000000..d571c7cf3 --- /dev/null +++ b/hasura/migrations/1705715523486_alter_table_public_eula_acceptances_alter_column_address/up.sql @@ -0,0 +1 @@ +alter table "public"."eula_acceptances" alter column "address" drop not null;