From 8ad5cff0d109ed6e4aa73c33d20df7a9ee0bc099 Mon Sep 17 00:00:00 2001 From: CptTony Date: Mon, 5 Jun 2023 14:16:16 -0400 Subject: [PATCH 1/2] Merge pull request #1693 from ActiveLearningStudio/feature/fix-search-library fix search --- src/components/Search/SearchLibrary.js | 125 ++++--- src/containers/Search/index.js | 480 +++++++++++++------------ 2 files changed, 325 insertions(+), 280 deletions(-) diff --git a/src/components/Search/SearchLibrary.js b/src/components/Search/SearchLibrary.js index ea3c52b8b..da819705a 100644 --- a/src/components/Search/SearchLibrary.js +++ b/src/components/Search/SearchLibrary.js @@ -5,6 +5,7 @@ import PropTypes from "prop-types"; import { Accordion, Card } from "react-bootstrap"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import Swal from "sweetalert2"; +import { setSearchTypeAction } from "store/actions/search"; const SearchLibrary = (props) => { const { @@ -44,6 +45,8 @@ const SearchLibrary = (props) => { noWords, setisLoader, activeModel, + searchTypeNew, + setSearchActivityNew, } = props; const onSubmit = async () => { @@ -54,10 +57,10 @@ const SearchLibrary = (props) => { setActiveTab(fromTeam ? "projects" : "Independent activities"); if (searchInput?.length > 255) { Swal.fire("Character limit should be less than 255."); - } else if ( - activeMainSearchType === "Projects" || - activeMainSearchType === "projects" - ) { + return; + } + + if (true) { // Swal.fire({ // title: 'Searching...', // add html attribute if you want or remove // html: 'We are fetching results for you!', @@ -66,28 +69,33 @@ const SearchLibrary = (props) => { // Swal.showLoading(); // }, // }); - const dataSend = { - phrase: searchInput?.trim(), + let dataSend; + // eslint-disable-next-line prefer-const + dataSend = { + query: searchInput?.trim(), subjectArray: activeSubject, gradeArray: activeEducation, authorTagsArray: activeAuthorTag, + authors: authorName || undefined, standardArray: activeType, - author: authorName || undefined, - fromDate: fromdate || undefined, - toDate: todate || undefined, - type: searchType, from: 0, + model: + activeModel === "total" + ? undefined + : activeModel || undefined, size: 20, - model: "projects", no_words: noWords || undefined, }; - console.log("dataSend", dataSend); - const result = await dispatch(simpleSearchAction(dataSend)); - setTotalCount(result.meta?.projects); + const result = await dispatch( + searchIndependentActivitiesAction( + dataSend, + "showcase_activities" + ) + ); + setTotalCount(result?.meta?.total); const tempEducation = []; const tempSubject = []; const tempTag = []; - const tempAuthor = []; if (activeEducation) { activeEducation.forEach((edu) => { if (String(edu).includes("&")) { @@ -114,12 +122,12 @@ const SearchLibrary = (props) => { activeAuthorTag.forEach((sub) => { if (String(sub).includes("&")) { const temp = String(sub).replace("&", "and"); - tempAuthor.push(temp); + tempTag.push(temp); } else { - tempAuthor.push(sub); + tempTag.push(sub); } }); - setActiveAuthorTag(tempAuthor); + setActiveAuthorTag(tempTag); } if (!fromTeam) { // eslint-disable-next-line max-len @@ -129,7 +137,9 @@ const SearchLibrary = (props) => { // }/search?q=${searchInput.trim()}&type=${searchType}&grade=${tempSubject}&education=${tempEducation}&authorTag=${tempTag}&h5p=${activeType}&author=${authorName}`, // ); } - } else if (activeMainSearchType === "Independent activities") { + } + + if (true) { // Swal.fire({ // title: 'Searching...', // add html attribute if you want or remove // html: 'We are fetching results for you!', @@ -138,33 +148,33 @@ const SearchLibrary = (props) => { // Swal.showLoading(); // }, // }); - let dataSend; - // eslint-disable-next-line prefer-const - dataSend = { - query: searchInput?.trim(), + const dataSend = { + phrase: searchInput?.trim(), subjectArray: activeSubject, gradeArray: activeEducation, authorTagsArray: activeAuthorTag, - authors: authorName || undefined, standardArray: activeType, + author: authorName || undefined, + fromDate: fromdate || undefined, + toDate: todate || undefined, + type: "projects", from: 0, - model: - activeModel === "total" - ? undefined - : activeModel || undefined, size: 20, + model: "projects", no_words: noWords || undefined, }; - const result = await dispatch( - searchIndependentActivitiesAction( - dataSend, - "showcase_activities", - ), - ); - setTotalCount(result?.meta?.total); + //if (searchTypeNew === "Independent activities") { + dispatch(setSearchTypeAction("projects")); + // } else { + // dispatch(setSearchTypeAction("Independent activities")); + // } + + const result = await dispatch(simpleSearchAction(dataSend)); + setTotalCount(result.meta?.projects); const tempEducation = []; const tempSubject = []; const tempTag = []; + const tempAuthor = []; if (activeEducation) { activeEducation.forEach((edu) => { if (String(edu).includes("&")) { @@ -191,12 +201,12 @@ const SearchLibrary = (props) => { activeAuthorTag.forEach((sub) => { if (String(sub).includes("&")) { const temp = String(sub).replace("&", "and"); - tempTag.push(temp); + tempAuthor.push(temp); } else { - tempTag.push(sub); + tempAuthor.push(sub); } }); - setActiveAuthorTag(tempTag); + setActiveAuthorTag(tempAuthor); } if (!fromTeam) { // eslint-disable-next-line max-len @@ -207,6 +217,7 @@ const SearchLibrary = (props) => { // ); } } + dispatch(setSearchTypeAction("Independent activities")); // setModalShow(true); }; @@ -214,19 +225,17 @@ const SearchLibrary = (props) => { setSearchInput(""); setNoWords(""); setAuthor(""); + setSearch([]); + setSearchActivityNew([]); setActiveEducation([]); setActiveSubject([]); setActiveAuthorTag([]); setActiveType([]); // onSubmit(); - const result = await dispatch(simpleSearchAction({})); - const result1 = await dispatch( - searchIndependentActivitiesAction( - {}, - "showcase_activities", - ), - ); - + // const result = await dispatch(simpleSearchAction({})); + // const result1 = await dispatch( + // searchIndependentActivitiesAction({}, "showcase_activities") + // ); }; return ( @@ -311,11 +320,29 @@ const SearchLibrary = (props) => { }} /> -
-
clearFilters()}> +
+
clearFilters()} + > Clear All
-
onSubmit()}> +
onSubmit()} + > Search
diff --git a/src/containers/Search/index.js b/src/containers/Search/index.js index 3ce7b6bea..47fc16096 100644 --- a/src/containers/Search/index.js +++ b/src/containers/Search/index.js @@ -133,6 +133,8 @@ function SearchInterface(props) { const [modalShow, setModalShow] = useState(false); const [modalShowActivity, setModalShowActivity] = useState(false); const [search, setSearch] = useState(null); + const [searchActivity, setSearchActivity] = useState([]); + const [activityModal, setActivityModal] = useState([]); const [searchQueries, SetSearchQuery] = useState(""); const [searchInput, setSearchInput] = useState(""); const [meta, setMeta] = useState({}); @@ -229,7 +231,12 @@ function SearchInterface(props) { useEffect(() => { if (allState?.searchResult) { if (allState.searchResult?.length > 0) { - setSearch(allState.searchResult); + if (allState.searchType === "Independent activities") { + setSearchActivity(allState); + } else { + setSearch(allState.searchResult); + } + SetSearchQuery(allState.searchQuery); setSearchInput(allState.searchQuery); setMeta(allState.searchMeta); @@ -323,6 +330,9 @@ function SearchInterface(props) { ); resultAuth.then((data) => setAuthorTags(data)); } + !!search && + !!meta.total && + activeModel === "Independent activities"; if (educationLevels?.length === 0) { const resultEdu = dispatch( getEducationLevel(currentOrganization?.id || 1) @@ -442,6 +452,8 @@ function SearchInterface(props) { setNoWords={setNoWords} setisLoader={setisLoader} activeModel={activeModel} + searchTypeNew={allState.searchType} + setSearchActivityNew={setSearchActivity} />
{ - setisLoader(true); - if (eventKey === "Independent activities") { - setActiveModel("Independent activities"); - const searchData = { - query: searchInput?.trim(), - subjectArray: activeSubject, - gradeArray: activeEducation, - authorTagsArray: activeAuthorTag, - authors: authorName || undefined, - standardArray: activeType, - from: 0, - size: 20, - no_words: noWords || undefined, - }; + // onSelect={async (eventKey) => { + // setisLoader(true); + // if (eventKey === "Independent activities") { + // setActiveModel("Independent activities"); + // const searchData = { + // query: searchInput?.trim(), + // subjectArray: activeSubject, + // gradeArray: activeEducation, + // authorTagsArray: activeAuthorTag, + // authors: authorName || undefined, + // standardArray: activeType, + // from: 0, + // size: 20, + // no_words: noWords || undefined, + // }; - setSearch(null); - await dispatch( - searchIndependentActivitiesAction( - searchData, - "showcase_activities" - ) - ); - } else { - setActiveModel(""); - // if (allState.searchType === "Projects") { - // if (activeModel === "projects") { - // { - const searchData = { - phrase: searchQueries?.trim(), - from: 0, - size: 20, - type: searchType, - model: eventKey, - subjectArray: - activeSubject || undefined, - gradeArray: - activeEducation || undefined, - authorTagsArray: - activeAuthorTag || undefined, - standardArray: activeType || undefined, - author: authorName || undefined, - no_words: noWords || undefined, - }; - setSearch(null); - await dispatch( - simpleSearchAction(searchData) - ); - Swal.close(); - // } - // } - } - dispatch(setSearchTypeAction(eventKey)); - // setSearchInput(""); + // setSearch(null); + // await dispatch( + // searchIndependentActivitiesAction( + // searchData, + // "showcase_activities" + // ) + // ); + // } else { + // setActiveModel(""); + // // if (allState.searchType === "Projects") { + // // if (activeModel === "projects") { + // // { + // const searchData = { + // phrase: searchQueries?.trim(), + // from: 0, + // size: 20, + // type: searchType, + // model: eventKey, + // subjectArray: + // activeSubject || undefined, + // gradeArray: + // activeEducation || undefined, + // authorTagsArray: + // activeAuthorTag || undefined, + // standardArray: activeType || undefined, + // author: authorName || undefined, + // no_words: noWords || undefined, + // }; + // setSearch(null); + // await dispatch( + // simpleSearchAction(searchData) + // ); + // Swal.close(); + // // } + // // } + // } + // dispatch(setSearchTypeAction(eventKey)); + // // setSearchInput(""); - // setNoWords(""); - setSearchType(""); - // setSearch(null); - // setTotalCount(0); - setActivePage(1); - // setMeta({}); - setToggleStates({ - searchLibrary: true, - subject: true, - education: false, - authorTag: false, - type: false, - }); - // setActiveSubject([]); - // setActiveEducation([]); - // setActiveAuthorTag([]); - // SetAuthor([]); - Settodate([]); - Setfromdate([]); - setisLoader(false); - // setActiveType([]); - }} + // // setNoWords(""); + // setSearchType(""); + // // setSearch(null); + // // setTotalCount(0); + // setActivePage(1); + // // setMeta({}); + // setToggleStates({ + // searchLibrary: true, + // subject: true, + // education: false, + // authorTag: false, + // type: false, + // }); + // // setActiveSubject([]); + // // setActiveEducation([]); + // // setActiveAuthorTag([]); + // // SetAuthor([]); + // Settodate([]); + // Setfromdate([]); + // setisLoader(false); + // // setActiveType([]); + // }} defaultActiveKey={ !fromTeam ? allState.searchType : "Projects" } @@ -552,176 +564,182 @@ function SearchInterface(props) { {!fromTeam && (
- {!!search ? ( - search?.length > 0 ? ( - search.map((res) => ( - <> -
-
- {res?.thumb_url ? ( -
- ) : ( -
- )} + {!!searchActivity ? ( + searchActivity?.searchResult + ?.length > 0 ? ( + searchActivity?.searchResult.map( + (res) => ( + <> +
+
+ {res?.thumb_url ? ( +
+ ) : ( +
+ )} - {/*
CALCULUS
*/} -
+ {/*
CALCULUS
*/} +
-
-
- -

- {res.title || - res.name} -

-
-

{res.description}

- {res.user && ( -
- By:{" "} - +
+
+ +

+ {res.title || + res.name} +

+
+

+ {res.description} +

+ {res.user && ( +
+ By:{" "} + + { + res.user + .first_name + } + +
+ )} +
+ Type:{" "} + { - res.user - .first_name + res.activity_type }
- )} -
- Type:{" "} - - {res.activity_type} - + {/*

{res.description}

*/}
- {/*

{res.description}

*/} -
- {true && ( - - - - - - <> - - {/* + {true && ( + + + + + + <> + + {/* Preview */} -
- - - Preview - -
-
- { - toast.info( - "Duplicating Activity...", - { - className: - "project-loading", - closeOnClick: false, - closeButton: false, - position: - toast - .POSITION - .BOTTOM_RIGHT, - autoClose: 10000, - icon: "", - } - ); +
+ + + Preview + +
+ + { + toast.info( + "Duplicating Activity...", + { + className: + "project-loading", + closeOnClick: false, + closeButton: false, + position: + toast + .POSITION + .BOTTOM_RIGHT, + autoClose: 10000, + icon: + "", + } + ); - const result = await intActivityServices.indActivityClone( - currentOrganization?.id, - res.id - ); + const result = await intActivityServices.indActivityClone( + currentOrganization?.id, + res.id + ); - toast.dismiss(); - Swal.fire({ - html: - result.message, - icon: - "success", - }); - }} - > -
- - Copy to My - Activities -
-
- { - setIndClone( - true - ); - setModalShow( - true - ); - setClone(res); - }} - > - {/* + toast.dismiss(); + Swal.fire({ + html: + result.message, + icon: + "success", + }); + }} + > +
+ + Copy to My + Activities +
+
+ { + setIndClone( + true + ); + setModalShow( + true + ); + setClone( + res + ); + }} + > + {/* Add to Projects */} -
- - Copy to My - projects -
-
- -
-
- )} +
+ + Copy to My + projects +
+ + + + + )} +
-
- - )) + + ) + ) ) : ( No result found ! @@ -744,7 +762,7 @@ function SearchInterface(props) { eventKey="projects" title={ !!search && !!meta.projects - ? `projects (${meta.projects})` + ? `projects (${meta.projects || 0})` : "projects (0)" } > From 08a9bdd15f584d6603592237f233c03d34c59616 Mon Sep 17 00:00:00 2001 From: CptTony Date: Fri, 9 Jun 2023 14:02:20 -0400 Subject: [PATCH 2/2] Merge pull request #1696 from ActiveLearningStudio/feature/msteams-integration-staging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge pull request #1695 from ActiveLearningStudio/feature/msteams-in… --- src/containers/LMS/MsTeams/MsTeamsActivityContainer/index.js | 2 +- src/containers/MsTeams/callback.js | 3 ++- src/services/msTeams.service.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/containers/LMS/MsTeams/MsTeamsActivityContainer/index.js b/src/containers/LMS/MsTeams/MsTeamsActivityContainer/index.js index 79828d595..c607e294e 100644 --- a/src/containers/LMS/MsTeams/MsTeamsActivityContainer/index.js +++ b/src/containers/LMS/MsTeams/MsTeamsActivityContainer/index.js @@ -121,7 +121,7 @@ function MsTeamsActivityContainer({ match, history }) { const params = new URLSearchParams(); params.append('client_id', config.teamsClientId); params.append('response_type', 'code'); - params.append('scope', 'offline_access user.read mail.read'); + params.append('scope', 'offline_access user.read'); params.append('redirect_uri', `https://${window.location.hostname}/msteams/callback`); params.append('state', window.location.href); url.search = params.toString(); diff --git a/src/containers/MsTeams/callback.js b/src/containers/MsTeams/callback.js index b2d1db176..b099a2634 100644 --- a/src/containers/MsTeams/callback.js +++ b/src/containers/MsTeams/callback.js @@ -13,11 +13,12 @@ const MsTeamsCallBack = () => { const params = new URLSearchParams(useLocation().search); const code = params.get('code'); const state = params.get('state'); + const tenantId = state.split('msteam/')[1].split('/launch')[0]; const [error, setError] = useState(null); // Get app context and auth token useEffect(() => { - MsTeamsService.msTeamsToken(code) + MsTeamsService.msTeamsToken(code, tenantId) .then((response) => { localStorage.setItem('msteams_token', response.access_token); localStorage.setItem('msteams_refresh_token', response.refresh_token); diff --git a/src/services/msTeams.service.js b/src/services/msTeams.service.js index 9ab921094..27b17b325 100644 --- a/src/services/msTeams.service.js +++ b/src/services/msTeams.service.js @@ -3,11 +3,12 @@ import config from 'config'; import httpService from './http.service'; const { apiVersion } = config; -const msTeamsToken = (code) => httpService +const msTeamsToken = (code, tenantId) => httpService .get(`/microsoft-team/get-access-token-via-code`, {}, { code: code, + tenantId: tenantId, }) .then(({ data }) => data) .catch((err) => Promise.reject(err.response.data));