From 8e8797418ae535f66d75cb8728006fca16200b50 Mon Sep 17 00:00:00 2001 From: "robert.bond@test.gov.wales" Date: Tue, 7 Sep 2021 12:46:59 +0100 Subject: [PATCH] added crm driven form via oauth --- actions/index.js | 136 +++++++++++++++++++++----- components/elements/index.js | 35 ++----- components/newappeal/buildcheckrow.js | 76 +++++++------- components/newappeal/buildfield.js | 1 + components/newappeal/buildrow.js | 32 +++--- components/newappeal/createCase.js | 45 +++------ pages/newappeal/[appealtypes].js | 26 +++-- pages/searchresults.js | 9 +- store/formData/action.js | 15 +-- store/formData/reducer.js | 4 + store/searchOutput/action.js | 8 ++ store/searchOutput/reducer.js | 7 ++ 12 files changed, 245 insertions(+), 149 deletions(-) diff --git a/actions/index.js b/actions/index.js index 015e296e..1ab22b86 100644 --- a/actions/index.js +++ b/actions/index.js @@ -13,6 +13,10 @@ if (process.browser) { BASE_URL = process.env.API_ROOT || `http://localhost:${port}`; } +const WEBAPI_URL = "https://devcrm2016.llcdt.gov.wales/DVPINS"; + +const API_PATH = "/api/data/v8.2/"; + const agent = new https.Agent({ rejectUnauthorized: false, }); @@ -24,11 +28,8 @@ const crmHeaders = { "OData-Version": "4.0", "Accept": "application/json", "Prefer": 'odata.include-annotations="*"', - agent, - }, - auth: { - username: "xm\bondr", - password: "!Sky9fish1972", + "Authorization": + "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSIsImtpZCI6IlVXelVaa0U3OEx0NVBGRkJ0LV9seVdoMjdjTSJ9.eyJhdWQiOiJodHRwczovL2RldmNybTIwMTYubGxjZHQuZ292LndhbGVzLyIsImlzcyI6Imh0dHA6Ly9mcy50ZXN0Lmdvdi53YWxlcy9hZGZzL3NlcnZpY2VzL3RydXN0IiwiaWF0IjoxNjMxMDAwMjUxLCJuYmYiOjE2MzEwMDAyNTEsImV4cCI6MTYzMTAyOTA1MSwidXBuIjpbIlJvYmVydC5Cb25kQHRlc3QuZ292LndhbGVzIiwicm9iZXJ0LmJvbmRAdGVzdC5nb3Yud2FsZXMiXSwicHJpbWFyeXNpZCI6IlMtMS01LTIxLTE4MDA4NDIwNzYtMjQ1NTYwNjU5LTQyMTU3NzU0NjktMTY2MjgiLCJ1bmlxdWVfbmFtZSI6IlhNXFxCb25kUiIsImFwcHR5cGUiOiJQdWJsaWMiLCJhcHBpZCI6IjQyN2ZhNzljLWI1ZmMtNDJhZC04M2Q0LTQxMGIwMzk0OGFiNiIsImF1dGhtZXRob2QiOiJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvYXV0aGVudGljYXRpb25tZXRob2Qvd2luZG93cyIsImF1dGhfdGltZSI6IjIwMjEtMDktMDdUMDc6Mzc6MjIuMzM3WiIsInZlciI6IjEuMCJ9.L8husDSMXMtZxpxKDS0cpPplG6xoHQjSdd17qMfgKZaEUPUOKPy4rznxNwAMp7WxussNeK__nOKE9vHNgc5Nk4lzxbvcYy3jeE7bLWHsB5UYFa1FIrPZpzuEdPIgoWAzhTa4k-anzsA0YNMHpV6QHT14F9wkBTsT8MUtpT2BiNfbflQQ_xtQavp_pCww-1-guysM6USv5NJkuvrHpXjA5_HpaGbprLI8Or3Htjsdgq9c4uCxfjoAGZsjUmtvaIL-jQnkR6-ndYezo12tes7ql2iV4iZT4-fvcib8sUdzHkgFvNmyzMblhogUo8QciTBcvF7-syCfNzLG2vvWSZJ9_g", }, }; @@ -39,9 +40,17 @@ export const getBasicSearch = (searchString) => { axios //.get("https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=contains(title, '" + searchString + "')&$count=true", crmHeaders) //.get("https://jsonplaceholder.typicode.com/todos/1",{proxy:{protocol: 'http',host:'lon3.sme.zscloud.net',port: 80}}) - .get(BASE_URL + "/api/searchresults2", { - httpsAgent: new https.Agent({ rejectUnauthorized: false }), - }) + // .get(BASE_URL + "/api/searchresults2", { + // httpsAgent: new https.Agent({ rejectUnauthorized: false }), + // }) + .get( + WEBAPI_URL + + API_PATH + + "incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=contains(title, '" + + searchString + + "')&$count=true", + crmHeaders + ) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -49,6 +58,24 @@ export const getBasicSearch = (searchString) => { ); }; +export const getBasicSearchDetails = (appealType, caseReference) => { + return axios + .get( + WEBAPI_URL + + API_PATH + + "/pinswg_ " + + appealType + + "?$filter=pinswg_name eq '" + + caseReference + + "'&$count=true", + crmHeaders + ) + .then((res) => res.data) + .catch((error) => { + console.log("thiserror", error); + }); +}; + export const getFormData = (whichForm) => { console.log("got to axios", whichForm); console.log("api_root: ", BASE_URL); @@ -62,9 +89,18 @@ export const getFormData = (whichForm) => { //.get("api/appealforms/pinswg_harbourrevisionorder", { //.get("api/appealforms/pinswg_planningappeals78", { //.get(api/appealforms/pinswg_householderappealhas", { - .get(BASE_URL + "/api/appealforms/pinswg_" + whichForm, { - httpsAgent: new https.Agent({ rejectUnauthorized: false }), - }) + // .get(BASE_URL + "/api/appealforms/pinswg_" + whichForm, { + // httpsAgent: new https.Agent({ rejectUnauthorized: false }), + // }) + + .get( + WEBAPI_URL + + API_PATH + + "systemforms?$select=formid,name,formxml,type,objecttypecode&$filter=(objecttypecode%20eq%20%27pinswg_" + + whichForm + + "%27and%20type%20eq%202)&$count=true", + crmHeaders + ) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -72,19 +108,59 @@ export const getFormData = (whichForm) => { ); }; -export const getAppealsTypes = () => { - console.log("got to axios: appeal types"); - console.log("api_root: ", BASE_URL); +export const getMandatoryFields = (whichForm) => { return axios - .get(BASE_URL + "/api/lookups/pinswg_appealcasetype", { - httpsAgent: new https.Agent({ rejectUnauthorized: false }), - }) + .get( + WEBAPI_URL + + API_PATH + + "EntityDefinitions(LogicalName='pinswg_" + + whichForm + + "')/Attributes?$count=true&$select=LogicalName,RequiredLevel", + crmHeaders + ) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); }); }; +export const getPickLists = (whichForm) => { + return axios + .get( + WEBAPI_URL + + API_PATH + + "EntityDefinitions(LogicalName='pinswg_" + + whichForm + + "')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet&$count=true", + crmHeaders + ) + .then((res) => res.data) + .catch((error) => { + console.log("thiserror", error); + }); +}; + +export const getAppealsTypes = () => { + console.log("got to axios: appeal types"); + console.log("api_root: ", BASE_URL); + return ( + axios + // .get(BASE_URL + "/api/lookups/pinswg_appealcasetype", { + // httpsAgent: new https.Agent({ rejectUnauthorized: false }), + // }) + .get( + WEBAPI_URL + + API_PATH + + "stringmaps?$filter=attributename%20eq%20%27pinswg_appealcasetype%27&$count=true&$select=value,stringmapid,organizationid,attributevalue", + crmHeaders + ) + .then((res) => res.data) + .catch((error) => { + console.log("thiserror", error); + }) + ); +}; + export const getBasicSearch2 = (searchString) => { var req = new XMLHttpRequest(); req.open( @@ -189,17 +265,23 @@ export const getAppealTypeDetail = (caseReference, appealcasetype) => { export const getLPA = () => { console.log("api_root: ", BASE_URL); - return axios + return ( + axios - .get( - BASE_URL + "/api/lookups/pinswg_lpa", - //.get("https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/accounts?$select=name", - { httpsAgent: new https.Agent({ rejectUnauthorized: false }) } - ) - .then((res) => res.data) - .catch((error) => { - console.log("thi serror", error); - }); + // .get( + // BASE_URL + "/api/lookups/pinswg_lpa", + // //.get("https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/accounts?$select=name", + // { httpsAgent: new https.Agent({ rejectUnauthorized: false }) } + // ) + .get( + WEBAPI_URL + API_PATH + "accounts?$count=true&$select=name", + crmHeaders + ) + .then((res) => res.data) + .catch((error) => { + console.log("thi serror", error); + }) + ); }; export const getPersonalAccount = () => { diff --git a/components/elements/index.js b/components/elements/index.js index 60e6afe2..207c2036 100644 --- a/components/elements/index.js +++ b/components/elements/index.js @@ -5,6 +5,7 @@ import DatePicker from "react-datepicker"; import React, { useState } from "react"; import "react-datepicker/dist/react-datepicker.css"; import moment from "moment"; +import jsonpath from "jsonpath"; const RenderTextfield = ({ id, @@ -356,35 +357,17 @@ export function YesNofield(props) { const RenderPickList = ({ datafieldname, + picklistData, name, label, input, meta: { touched, errorStr }, }) => { - const fetcher = (url) => fetch(url).then((res) => res.json()); - - const { data, error } = useSWR("/api/lookups/" + datafieldname, fetcher); - if (error) - return ( -
- - -
- ); - if (!data) - return ( -
-
{label} loading...
-
- ); - //console.log(JSON.stringify(data.GlobalOptionSet.Options)); - - const dropdownObj = data.GlobalOptionSet.Options; - + var dropdownObj = jsonpath.query( + picklistData, + "$..value[?(@.LogicalName=='" + datafieldname + "')]..Options" + ); + dropdownObj = dropdownObj[0]; return (