Skip to content

Commit

Permalink
Merge branch 'develop' into feat/VIC-646-enable-2FA-admin-UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Soarecos committed Jun 8, 2022
2 parents 419ca64 + dcd9496 commit bae62a0
Show file tree
Hide file tree
Showing 67 changed files with 16,113 additions and 14,058 deletions.
5 changes: 0 additions & 5 deletions .env.local

This file was deleted.

8 changes: 7 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
PORT=9000
BROWSER=none

REACT_APP_CSRF_WHITELIST_HEADER_FOR_LOCAL_DEVELOPMENT=TOKEN
REACT_APP_API_URL=develop.myDomain.net
REACT_APP_API_URL=develop.myDomain.net

# OPTIONAL

# forces the usage of the api url for all api calls # e.g. useful for local development
# REACT_APP_USE_API_URL=true
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"react/react-in-jsx-scope": "off",
"valid-jsdoc": "off",
"react/jsx-fragments": "off",
"react-hooks/exhaustive-deps": "off",
"react/no-array-index-key": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-types": "off",
Expand All @@ -45,7 +47,7 @@
},
"settings": {
"react": {
"version": "latest"
"version": "detect"
},
" import/resolver": {
"node": {
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ yarn-debug.log*
yarn-error.log*
/.idea/
.history

.env
960 changes: 498 additions & 462 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import routePathNames from "./appConfig";
// import Dashboard from "./pages/Dashboard";
import TenantSettings from "./pages/TenantSettings";
import Counselors from "./pages/Counselors";
import Topics from "./pages/Topics";
import UserProfile from "./pages/UserProfile";
import Tenants from "./pages/Tenants";
import pubsub, { PubSubEvents } from "./state/pubsub/PubSub";
import Initialisation from "./components/Layout/Initialisation";
import Agencies from "./pages/Agencies";

function App() {
const [renderAppComponent, setRenderAppComponent] = useState(false);
Expand All @@ -35,6 +37,8 @@ function App() {
element={<TenantSettings />}
/>
<Route path={routePathNames.counselors} element={<Counselors />} />
<Route path={routePathNames.agency} element={<Agencies />} />
<Route path={routePathNames.topics} element={<Topics />} />
<Route path={routePathNames.userProfile} element={<UserProfile />} />
<Route path={routePathNames.tenants} element={<Tenants />} />
</Routes>
Expand Down
55 changes: 55 additions & 0 deletions src/api/agency/addAgencyData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { FETCH_ERRORS, FETCH_METHODS, fetchData } from "../fetchData";
import { agencyEndpointBase } from "../../appConfig";
import updateAgencyPostCodeRange from "./updateAgencyPostCodeRange";
import getConsultingType4Tenant from "../consultingtype/getConsultingType4Tenant";

function buildAgencyDataRequestBody(
consultingTypeResponseId: string,
formData: Record<string, any>
) {
return JSON.stringify({
// diocese in case of SAAS is not relevant object but enforced by API
dioceseId: 0,
name: formData.name,
description: formData.description,
postcode: formData.postcode,
city: formData.city,
consultingType: consultingTypeResponseId,
teamAgency: formData.teamAgency ? formData.teamAgency : false,
// enforced by admin API, without business value for SAAS
external: false,
offline: formData.offline,
});
}

async function createAgency(agencyDataRequestBody: string) {
return fetchData({
url: agencyEndpointBase,
method: FETCH_METHODS.POST,
skipAuth: false,
responseHandling: [FETCH_ERRORS.CATCH_ALL],
bodyData: agencyDataRequestBody,
}).then((addAgencyResponse) => {
return addAgencyResponse.json();
});
}

/**
* add new agency
* @param agencyData
* @return data
*/
async function addAgencyData(agencyData: Record<string, any>) {
const consultingTypeId = await getConsultingType4Tenant();
const agencyDataRequestBody = buildAgencyDataRequestBody(
consultingTypeId,
agencyData
);
const agencyCreationResponse = await createAgency(agencyDataRequestBody);

// eslint-disable-next-line no-underscore-dangle
const { id } = agencyCreationResponse._embedded;
return updateAgencyPostCodeRange(id, agencyData, "POST");
}

export default addAgencyData;
21 changes: 21 additions & 0 deletions src/api/agency/deleteAgencyData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FETCH_ERRORS, FETCH_METHODS, fetchData } from "../fetchData";
import { agencyEndpointBase } from "../../appConfig";
import { AgencyData } from "../../types/agency";

/**
* delete agency
* @param agencyData
* @return Promise
*/
const deleteAgencyData = (agencyData: AgencyData) => {
const { id } = agencyData;

return fetchData({
url: `${agencyEndpointBase}/${id}`,
method: FETCH_METHODS.DELETE,
skipAuth: false,
responseHandling: [FETCH_ERRORS.CATCH_ALL],
});
};

export default deleteAgencyData;
21 changes: 0 additions & 21 deletions src/api/agency/deleteAgencyFromCounselor.ts

This file was deleted.

54 changes: 54 additions & 0 deletions src/api/agency/getAgencyData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { agencyEndpointBase } from "../../appConfig";

import { FETCH_METHODS, fetchData } from "../fetchData";
import removeEmbedded from "../../utils/removeEmbedded";

export const DEFAULT_SORT = "NAME";
export const DEFAULT_ORDER = "ASC";

/**
* retrieve all agencies for tenant context
* @return {Promise}
*/
const getAgencyData = (params: TableState) => {
// retrieve Agencies

let sortBy = params.sortBy || DEFAULT_SORT;
let order = params.order || DEFAULT_ORDER;

sortBy = sortBy.toUpperCase();
order = order.toUpperCase();

const resolveAgencyStatus = (el: any) => {
if (el.deleteDate !== "null") {
return "IN_DELETION";
}
return "CREATED";
};

return fetchData({
url: `${agencyEndpointBase}/?page=${params.current}&perPage=10&order=${order}&field=${sortBy}`,
method: FETCH_METHODS.GET,
skipAuth: false,
responseHandling: [],
})
.then((result) => {
// eslint-disable-next-line no-underscore-dangle
return removeEmbedded(result);
})
.then((result) => {
return {
total: result.total,
data: result.data.map((el: any) => {
return {
...el,
teamAgency: el.teamAgency ? "true" : "false",
status: resolveAgencyStatus(el),
online: !el.offline,
};
}),
};
});
};

export default getAgencyData;
38 changes: 38 additions & 0 deletions src/api/agency/getAgencyPostCodeRange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { FETCH_ERRORS, FETCH_METHODS, fetchData } from "../fetchData";
import { agencyPostcodeRangeEndpointBase } from "../../appConfig";

export interface PostCodeRange {
from: string;
until: string;
}

/**
* get postcode ranges of an agency
* @param id - agency id
* @return data
*/
const getAgencyPostCodeRange = (id: string) => {
return fetchData({
url: `${agencyPostcodeRangeEndpointBase}/${id}`,
method: FETCH_METHODS.GET,
skipAuth: false,
responseHandling: [FETCH_ERRORS.CATCH_ALL],
}).then((data) => {
const result: PostCodeRange[] = [];
// eslint-disable-next-line no-underscore-dangle
data._embedded.postcodeRanges.split(";").forEach((el: string) => {
if (el === "") {
return;
}
const items = el.split("-");
result.push({
from: items[0],
until: items[1],
});
});

return result;
});
};

export default getAgencyPostCodeRange;
20 changes: 20 additions & 0 deletions src/api/agency/hasAgencyConsultants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { FETCH_ERRORS, FETCH_METHODS, fetchData } from "../fetchData";
import { consultantsForAgencyEndpoint } from "../../appConfig";

/**
* has agency consultants
* @param id - agency id
* @return boolean
*/
const hasAgencyConsultants = (agencyId: string) => {
return fetchData({
url: `${consultantsForAgencyEndpoint}`.replaceAll("{agencyId}", agencyId),
method: FETCH_METHODS.GET,
skipAuth: false,
responseHandling: [FETCH_ERRORS.CATCH_ALL],
}).then((data) => {
return data.total > 0;
});
};

export default hasAgencyConsultants;
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@ import { counselorEndpoint } from "../../appConfig";

import { FETCH_ERRORS, FETCH_METHODS, fetchData } from "../fetchData";

export const DEFAULT_ROLE = "CONSULTANT_DEFAULT";

/**
* retrieve all needed agency data
* @return {Promise}
*/
const addAgencyToCounselor = (
counselorId: string,
agencyId: string | string[] | null
) => {
if (agencyId === null) {
throw new Error("agencyId must be non null");
}
const putAgenciesForCounselor = (counselorId: string, agencyIds: string[]) => {
const agencies = agencyIds.map((agencyId) => ({
agencyId,
role: DEFAULT_ROLE,
}));

return fetchData({
url: `${counselorEndpoint}/${counselorId}/agencies`,
method: FETCH_METHODS.POST,
method: FETCH_METHODS.PUT,
skipAuth: false,
responseHandling: [FETCH_ERRORS.CATCH_ALL],
bodyData: JSON.stringify({
agencyId,
role: "CONSULTANT_DEFAULT",
}),
bodyData: JSON.stringify(agencies),
});
};

export default addAgencyToCounselor;
export default putAgenciesForCounselor;
46 changes: 46 additions & 0 deletions src/api/agency/updateAgencyData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { FETCH_ERRORS, FETCH_METHODS, fetchData } from "../fetchData";
import { agencyEndpointBase } from "../../appConfig";
import { AgencyData } from "../../types/agency";
import updateAgencyPostCodeRange from "./updateAgencyPostCodeRange";
import updateAgencyType from "./updateAgencyType";
import getConsultingType4Tenant from "../consultingtype/getConsultingType4Tenant";

/**
* update agency
* @param agencyModel - agency data from backend
* @param formInput - input data from form
* @return data
*/
const updateAgencyData = async (
agencyModel: AgencyData,
formInput: AgencyData
) => {
const agencyId = agencyModel.id;
if (agencyId == null) {
throw Error("agency id must be set");
}

await updateAgencyType(agencyModel, formInput);
await updateAgencyPostCodeRange(agencyId, formInput, "PUT");

const consultingTypeId = await getConsultingType4Tenant();
const agencyDataRequestBody = {
dioceseId: 0,
name: formInput.name,
description: formInput.description,
postcode: formInput.postcode,
city: formInput.city,
consultingType: consultingTypeId,
offline: !formInput.online,
external: false,
};
return fetchData({
url: `${agencyEndpointBase}/${agencyModel.id}`,
method: FETCH_METHODS.PUT,
skipAuth: false,
responseHandling: [FETCH_ERRORS.CATCH_ALL],
bodyData: JSON.stringify(agencyDataRequestBody),
});
};

export default updateAgencyData;
Loading

0 comments on commit bae62a0

Please sign in to comment.