| @@ -20,7 +20,8 @@ import { ReactComponent as CloseIcon } from "../../../../assets/images/svg/close | |||
| import { useTranslation } from "react-i18next"; | |||
| import { | |||
| editProfile, | |||
| fetchAllProfiles, | |||
| editProfileAsAdmin, | |||
| fetchAllProfilesAsAdmin, | |||
| fetchMineProfile, | |||
| } from "../../../../store/actions/profile/profileActions"; | |||
| import { useDispatch, useSelector } from "react-redux"; | |||
| @@ -63,17 +64,17 @@ const EditProfile = (props) => { | |||
| const handleApiResponseSuccess = () => { | |||
| if (dynamicRouteMatches(PROFILE_PAGE)) dispatch(fetchMineProfile(userId)); | |||
| if (routeMatches(ADMIN_USERS_PAGE) || routeMatches(ADMIN_HOME_PAGE)) | |||
| dispatch(fetchAllProfiles()); | |||
| dispatch(fetchAllProfilesAsAdmin()); | |||
| props.reFetchProfile(); | |||
| }; | |||
| const handleSubmit = (values) => { | |||
| if (props.isAdmin) { | |||
| dispatch( | |||
| editProfile({ | |||
| editProfileAsAdmin({ | |||
| userId: props.userId, | |||
| ...values, | |||
| firmLogo: profileImage, | |||
| firmLogo: profileImage === props.profile.image ? null : profileImage, | |||
| handleApiResponseSuccess, | |||
| }) | |||
| ); | |||
| @@ -81,7 +82,7 @@ const EditProfile = (props) => { | |||
| dispatch( | |||
| editProfile({ | |||
| ...values, | |||
| firmLogo: profileImage, | |||
| firmLogo: profileImage === props.profile.image ? null : profileImage, | |||
| handleApiResponseSuccess, | |||
| }) | |||
| ); | |||
| @@ -178,6 +178,7 @@ const ProfileCard = (props) => { | |||
| {editProfileModal && ( | |||
| <EditProfile | |||
| profile={profile} | |||
| isAdmin={props.isAdmin} | |||
| closeModalHandler={closeModalHandler} | |||
| reFetchProfile={reFetchProfile} | |||
| /> | |||
| @@ -2,7 +2,7 @@ import React, { useEffect, useMemo } from "react"; | |||
| import PropTypes from "prop-types"; | |||
| import { useDispatch, useSelector } from "react-redux"; | |||
| import { selectAllProfiles } from "../../../store/selectors/profileSelectors"; | |||
| import { fetchAllProfiles } from "../../../store/actions/profile/profileActions"; | |||
| import { fetchAllProfilesAsAdmin } from "../../../store/actions/profile/profileActions"; | |||
| import { | |||
| AdminUsersHeader, | |||
| AdminUsersList, | |||
| @@ -21,7 +21,7 @@ const AdminUsersPage = () => { | |||
| [allUsers] | |||
| ); | |||
| useEffect(() => { | |||
| dispatch(fetchAllProfiles()); | |||
| dispatch(fetchAllProfilesAsAdmin()); | |||
| }, []); | |||
| const handleSearch = () => {}; | |||
| @@ -120,7 +120,9 @@ export default { | |||
| invite: "/users/invite", | |||
| getProfile: "users/", | |||
| editProfile: "users", | |||
| getAllProfiles: "users" | |||
| editProfileAsAdmin: "admin/users/{userId}", | |||
| getAllProfiles: "users", | |||
| getAllProfilesAsAdmin: "admin/users" | |||
| }, | |||
| applications: { | |||
| application: "/applications/{applicationUid}", | |||
| @@ -1,4 +1,4 @@ | |||
| import { getRequest, putRequest } from "."; | |||
| import { getRequest, putRequest, replaceInUrl } from "."; | |||
| import apiEndpoints from "./apiEndpoints"; | |||
| export const attemptFetchProfile = (payload) => | |||
| @@ -6,6 +6,13 @@ export const attemptFetchProfile = (payload) => | |||
| export const attemptFetchAllProfiles = () => | |||
| getRequest(apiEndpoints.users.getAllProfiles); | |||
| export const attemptFetchAllProfilesAsAdmin = () => | |||
| getRequest(apiEndpoints.users.getAllProfilesAsAdmin); | |||
| export const attemptEditProfile = (payload, requestData) => | |||
| putRequest(apiEndpoints.users.editProfile + "/" + payload, requestData); | |||
| export const attemptEditProfileAsAdmin = (payload, requestData) => | |||
| putRequest( | |||
| replaceInUrl(apiEndpoints.users.editProfileAsAdmin, { userId: payload }), | |||
| requestData | |||
| ); | |||
| @@ -16,6 +16,11 @@ export const PROFILE_ALL_FETCH = createFetchType(PROFILE_ALL_SCOPE); | |||
| export const PROFILE_ALL_SUCCESS = createSuccessType(PROFILE_ALL_SCOPE); | |||
| export const PROFILE_ALL_ERROR = createErrorType(PROFILE_ALL_SCOPE); | |||
| export const PROFILE_ALL_ADMIN_SCOPE = "PROFILE_ALL_ADMIN_SCOPE"; | |||
| export const PROFILE_ALL_ADMIN_FETCH = createFetchType(PROFILE_ALL_ADMIN_SCOPE); | |||
| export const PROFILE_ALL_ADMIN_SUCCESS = createSuccessType(PROFILE_ALL_ADMIN_SCOPE); | |||
| export const PROFILE_ALL_ADMIN_ERROR = createErrorType(PROFILE_ALL_ADMIN_SCOPE); | |||
| export const PROFILE_MINE_SCOPE = "PROFILE_MINE_SCOPE"; | |||
| export const PROFILE_MINE_FETCH = createFetchType(PROFILE_MINE_SCOPE); | |||
| export const PROFILE_MINE_FETCH_SUCCESS = createSuccessType(PROFILE_MINE_SCOPE); | |||
| @@ -30,4 +35,9 @@ export const PROFILE_EDIT = createFetchType(PROFILE_EDIT_SCOPE); | |||
| export const PROFILE_EDIT_SUCCESS = createSuccessType(PROFILE_EDIT_SCOPE); | |||
| export const PROFILE_EDIT_ERROR = createErrorType(PROFILE_EDIT_SCOPE); | |||
| const PROFILE_EDIT_ADMIN_SCOPE = "PROFILE_EDIT_ADMIN_SCOPE"; | |||
| export const PROFILE_EDIT_ADMIN = createFetchType(PROFILE_EDIT_ADMIN_SCOPE); | |||
| export const PROFILE_EDIT_ADMIN_SUCCESS = createSuccessType(PROFILE_EDIT_ADMIN_SCOPE); | |||
| export const PROFILE_EDIT_ADMIN_ERROR = createErrorType(PROFILE_EDIT_ADMIN_SCOPE); | |||
| export const PROFILE_CLEAR = createClearType("PROFILE_CLEAR"); | |||
| @@ -7,13 +7,19 @@ import { | |||
| PROFILE_SET, | |||
| PROFILE_SUCCESS, | |||
| PROFILE_EDIT, | |||
| PROFILE_MINE_FETCH_SUCCESS, | |||
| PROFILE_EDIT_SUCCESS, | |||
| PROFILE_MINE_FETCH_ERROR, | |||
| PROFILE_EDIT_ERROR, | |||
| PROFILE_EDIT_ADMIN, | |||
| PROFILE_EDIT_ADMIN_SUCCESS, | |||
| PROFILE_EDIT_ADMIN_ERROR, | |||
| PROFILE_MINE_FETCH_SUCCESS, | |||
| PROFILE_MINE_FETCH_ERROR, | |||
| PROFILE_ALL_FETCH, | |||
| PROFILE_ALL_SUCCESS, | |||
| PROFILE_ALL_ERROR, | |||
| PROFILE_ALL_ADMIN_FETCH, | |||
| PROFILE_ALL_ADMIN_SUCCESS, | |||
| PROFILE_ALL_ADMIN_ERROR, | |||
| PROFILE_ALL_SET, | |||
| } from "./profileActionConstants"; | |||
| @@ -43,6 +49,19 @@ export const fetchAllProfilesError = (payload) => ({ | |||
| payload, | |||
| }); | |||
| export const fetchAllProfilesAsAdmin = (payload) => ({ | |||
| type: PROFILE_ALL_ADMIN_FETCH, | |||
| payload, | |||
| }); | |||
| export const fetchAllProfilesAsAdminSuccess = (payload) => ({ | |||
| type: PROFILE_ALL_ADMIN_SUCCESS, | |||
| payload, | |||
| }); | |||
| export const fetchAllProfilesAsAdminError = (payload) => ({ | |||
| type: PROFILE_ALL_ADMIN_ERROR, | |||
| payload, | |||
| }); | |||
| export const fetchMineProfile = () => ({ | |||
| type: PROFILE_MINE_FETCH, | |||
| }); | |||
| @@ -64,6 +83,17 @@ export const editProfileError = () => ({ | |||
| type: PROFILE_EDIT_ERROR, | |||
| }); | |||
| export const editProfileAsAdmin = (payload) => ({ | |||
| type: PROFILE_EDIT_ADMIN, | |||
| payload, | |||
| }); | |||
| export const editProfileAsAdminSuccess = () => ({ | |||
| type: PROFILE_EDIT_ADMIN_SUCCESS, | |||
| }); | |||
| export const editProfileAsAdminError = () => ({ | |||
| type: PROFILE_EDIT_ADMIN_ERROR, | |||
| }); | |||
| export const clearProfile = () => ({ | |||
| type: PROFILE_CLEAR, | |||
| }); | |||
| @@ -1,7 +1,9 @@ | |||
| import { all, call, put, takeLatest, select } from "@redux-saga/core/effects"; | |||
| import { | |||
| attemptEditProfile, | |||
| attemptEditProfileAsAdmin, | |||
| attemptFetchAllProfiles, | |||
| attemptFetchAllProfilesAsAdmin, | |||
| attemptFetchProfile, | |||
| } from "../../request/profileRequest"; | |||
| import { | |||
| @@ -9,10 +11,16 @@ import { | |||
| PROFILE_MINE_FETCH, | |||
| PROFILE_EDIT, | |||
| PROFILE_ALL_FETCH, | |||
| PROFILE_EDIT_ADMIN, | |||
| PROFILE_ALL_ADMIN_FETCH, | |||
| } from "../actions/profile/profileActionConstants"; | |||
| import { | |||
| editProfileAsAdminError, | |||
| editProfileAsAdminSuccess, | |||
| editProfileError, | |||
| editProfileSuccess, | |||
| fetchAllProfilesAsAdminError, | |||
| fetchAllProfilesAsAdminSuccess, | |||
| fetchAllProfilesError, | |||
| fetchAllProfilesSuccess, | |||
| fetchErrorProfile, | |||
| @@ -59,37 +67,19 @@ function* fetchAllProfiles() { | |||
| } | |||
| } | |||
| function* changeMineProfile(payload) { | |||
| function* fetchAllProfilesAsAdmin() { | |||
| try { | |||
| // console.log(payload); | |||
| // let image; | |||
| // if (payload.payload.firmLogo) { | |||
| // image = payload.payload.firmLogo; | |||
| // } else if (payload.payload.firmLogo === "") { | |||
| // image = ""; | |||
| // } | |||
| // const reqData = { | |||
| // company: { | |||
| // name: payload.payload.firmName, | |||
| // PIB: payload.payload.firmPIB, | |||
| // contacts: { | |||
| // telephone: payload.payload.firmPhone.toString(), | |||
| // location: payload.payload.firmLocation ?? "", | |||
| // web: payload.payload.firmWebsite, | |||
| // }, | |||
| // }, | |||
| // image: image, | |||
| // }; | |||
| // if (payload.payload.firmLogo?.includes("https")) delete reqData.image; | |||
| // if (reqData.company.contacts.telephone.length === 0) | |||
| // delete reqData.company.contacts.telephone; | |||
| // if (reqData.company.contacts.location.length === 0) | |||
| // delete reqData.company.contacts.location; | |||
| // if (reqData.company.contacts.web.length === 0) | |||
| // delete reqData.company.contacts.web; | |||
| const data = yield call(attemptFetchAllProfilesAsAdmin); | |||
| if (data) yield put(setAllProfiles(data.data.users)); | |||
| yield put(fetchAllProfilesAsAdminSuccess()); | |||
| } catch (e) { | |||
| yield put(fetchAllProfilesAsAdminError()); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| function* changeMineProfile(payload) { | |||
| try { | |||
| const requestBody = new FormData(); | |||
| if (typeof payload.payload.firmLogo !== "string") | |||
| requestBody.append("file", payload.payload.firmLogo); | |||
| @@ -125,11 +115,46 @@ function* changeMineProfile(payload) { | |||
| } | |||
| } | |||
| function* changeProfileAsAdmin(payload) { | |||
| try { | |||
| const requestBody = new FormData(); | |||
| console.log(payload); | |||
| if (typeof payload.payload?.firmLogo !== "string") | |||
| requestBody.append("file", payload.payload.firmLogo); | |||
| requestBody.append("company[name]", payload.payload.firmName); | |||
| requestBody.append("company[PIB]", payload.payload.firmPIB); | |||
| if (payload.payload.firmPhone.toString().length !== 0) | |||
| requestBody.append( | |||
| "company[contacts][telephone]", | |||
| payload.payload.firmPhone | |||
| ); | |||
| if (payload.payload.firmLocation.toString().length !== 0) | |||
| requestBody.append( | |||
| "company[contacts][location]", | |||
| payload.payload.firmLocation | |||
| ); | |||
| if (payload.payload.firmWebsite.toString().length !== 0) | |||
| requestBody.append("company[contacts][web]", payload.payload.firmWebsite); | |||
| const userId = payload.payload.userId; | |||
| yield call(attemptEditProfileAsAdmin, userId, requestBody); | |||
| yield put(editProfileAsAdminSuccess()); | |||
| if (payload.payload.handleApiResponseSuccess) { | |||
| yield call(payload.payload.handleApiResponseSuccess); | |||
| } | |||
| } catch (e) { | |||
| yield put(editProfileAsAdminError()); | |||
| console.dir(e); | |||
| } | |||
| } | |||
| export default function* profileSaga() { | |||
| yield all([ | |||
| takeLatest(PROFILE_FETCH, fetchProfile), | |||
| takeLatest(PROFILE_MINE_FETCH, fetchMineProfile), | |||
| takeLatest(PROFILE_EDIT, changeMineProfile), | |||
| takeLatest(PROFILE_ALL_FETCH, fetchAllProfiles), | |||
| takeLatest(PROFILE_ALL_ADMIN_FETCH, fetchAllProfilesAsAdmin), | |||
| takeLatest(PROFILE_EDIT_ADMIN, changeProfileAsAdmin), | |||
| ]); | |||
| } | |||