Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import axios from "axios";
- import { BaseApiUrl } from "../constants/apiRoutes";
- import {
- PROFILE_LOAD,
- GET_STATE_LOAD,
- GET_GRADE_LOAD,
- GET_DISTRICT_LOAD,
- GET_VDC_MUNICIPALITY_LOAD,
- PROFILE_LOAD_SUBJECT,
- LOAD_GRADE_AND_SUBJECT,
- SET_MESSAGE,
- PROFILE_UPDATED_RESPONSE,
- TRANSACTION_FAILED,
- LOAD_APPROVED_SCHOOL,
- MAKE_PROFILE_PROS_EMPTY,
- USER_GOALS_RETRIEVED,
- USER_GOALS_SAVED,
- AUTHOR_PROFILE_LOAD,
- AUTHOR_PROFILE_COURSE_LOAD,
- UPDATE_FOLLOW_STATE
- } from "../reducers/types";
- import { isEmpty } from "../helpers/validator";
- import { setMessageWithDispatch } from "./commonAction";
- export const GetCurrentUser = () => dispatch => {
- axios.get(BaseApiUrl + "Users/GetOverallProfileDetail").then(
- resp => {
- if (resp.data.Success === true) {
- dispatch({
- type: PROFILE_LOAD,
- payload: {
- profileData: resp.data.Result.UserInfo,
- CourseProgress: resp.data.Result.ProgressInfo,
- EarnedBadges: resp.data.Result.BadgeSection,
- Certificates: resp.data.Result.Certificate,
- QuizScore: resp.data.Result.QuizScore,
- TotalBadgeCount: resp.data.Result.TotalBadgeCount
- }
- });
- } else {
- dispatch({
- type: SET_MESSAGE,
- payload: isEmpty(resp.data.Message)
- ? "Failed to load Learner."
- : resp.data.Message
- });
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to connect to the server.."
- });
- }
- );
- };
- // export const GetCurrentInstructor = () => dispatch => {
- // axios.get(BaseApiUrl + "Users/GetCurrentRegisteredUser").then(
- // resp => {
- // if (resp.data.Success === true) {
- // dispatch({
- // type: PROFILE_LOAD,
- // payload: resp.data
- // });
- // } else {
- // dispatch({
- // type: SET_MESSAGE,
- // payload: isEmpty(resp.data.Message)
- // ? "Failed to load Learner."
- // : resp.data.Message
- // });
- // }
- // },
- // err => {
- // dispatch({
- // type: SET_MESSAGE,
- // payload: "Failed to connect to the server.."
- // });
- // }
- // );
- // };
- export const GetGradesWithSubjectUpdatedInstructor = TeachingSubjects => dispatch => {
- axios
- .get(
- BaseApiUrl +
- "Users/GetGradesWithSubjectUpdatedInstructor/?" +
- "&TeachingSubjects=" +
- TeachingSubjects
- )
- .then(
- resp => {
- if (resp.data.Success === true) {
- dispatch({
- type: LOAD_GRADE_AND_SUBJECT,
- payload: resp.data
- });
- } else {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to load Grade with subjects."
- });
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to connect to the server.."
- });
- }
- );
- };
- export const GetGrades = () => dispatch => {
- axios.get(BaseApiUrl + "Mobile/GetGrades").then(resp => {
- dispatch(
- {
- type: GET_GRADE_LOAD,
- payload: resp.data.Result
- },
- err => {
- console.log("Failed to load grade ", err);
- }
- );
- });
- };
- export const GetApprovedSchoolList = searchText => dispatch => {
- axios
- .get(BaseApiUrl + "Institute/GetApprovedSchoolList/" + searchText)
- .then(resp => {
- dispatch(
- {
- type: LOAD_APPROVED_SCHOOL,
- payload: resp.data.Result
- },
- err => {
- console.log("Failed to load school ", err);
- }
- );
- });
- };
- export const GetStates = () => dispatch => {
- axios.get(BaseApiUrl + "Distributors/GetStates").then(resp => {
- dispatch(
- {
- type: GET_STATE_LOAD,
- payload: resp.data.Result
- },
- err => {
- console.log("Failed to load state ", err);
- }
- );
- });
- };
- export const GetDistrict = stateId => dispatch => {
- axios.get(BaseApiUrl + "Distributors/GetDistrict/" + stateId).then(resp => {
- dispatch(
- {
- type: GET_DISTRICT_LOAD,
- payload: resp.data.Result
- },
- err => {
- console.log("Failed to load district ", err);
- }
- );
- });
- };
- export const GetVdcMunicipality = districtId => dispatch => {
- axios
- .get(BaseApiUrl + "Distributors/GetVdcMunicipality/" + districtId)
- .then(resp => {
- dispatch(
- {
- type: GET_VDC_MUNICIPALITY_LOAD,
- payload: resp.data.Result
- },
- err => {
- console.log("Failed to load Vdc/Municipality ", err);
- }
- );
- });
- };
- export const GetSubject = gradeId => dispatch => {
- axios
- .get(BaseApiUrl + "Subjects/GetSubjectsByGradeId/?" + "&gradeId=" + gradeId)
- .then(resp => {
- dispatch(
- {
- type: PROFILE_LOAD_SUBJECT,
- payload: resp.data.Result
- },
- err => {
- console.log("Neema learning material data load error : ", err);
- }
- );
- });
- };
- export const ChangeEmailReactWeb = (email, password, callback) => dispatch => {
- axios({
- url:
- BaseApiUrl +
- "Users/ChangeUserEmail?newEmail=" +
- email +
- "&password=" +
- password +
- "&forMobile=false",
- method: "POST",
- headers: {
- "Content-Type": "application/json; charset=utf-8"
- }
- }).then(
- resp => {
- if (resp.data.Success) {
- dispatch({
- type: SET_MESSAGE,
- payload: resp.data.Message
- });
- // dispatch({
- // type: TRANSACTION_FAILED,
- // payload: true
- // });
- callback && callback(resp.data);
- } else {
- callback && callback(resp.data);
- // dispatch({
- // type: SET_MESSAGE,
- // payload: resp.data.Message
- // });
- // dispatch({
- // type: TRANSACTION_FAILED,
- // payload: false
- // });
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to change Email."
- });
- // dispatch({
- // type: TRANSACTION_FAILED,
- // payload: false
- // });
- }
- );
- };
- export const ChangePhoneNumber = (phoneNo, password, callback) => dispatch => {
- axios({
- url:
- BaseApiUrl +
- "Users/ChangeUserPhoneNumber?newNumber=" +
- phoneNo +
- "&password=" +
- password,
- method: "POST",
- headers: {
- "Content-Type": "application/json; charset=utf-8"
- }
- }).then(
- resp => {
- if (resp.data.Success) {
- dispatch({
- type: SET_MESSAGE,
- payload: resp.data.Message
- });
- // dispatch({
- // type: TRANSACTION_FAILED,
- // payload: true
- // });
- callback && callback(resp.data);
- } else {
- callback && callback(resp.data);
- // dispatch({
- // type: SET_MESSAGE,
- // payload: resp.data.Message
- // });
- // dispatch({
- // type: TRANSACTION_FAILED,
- // payload: false
- // });
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to change Email."
- });
- // dispatch({
- // type: TRANSACTION_FAILED,
- // payload: false
- // });
- }
- );
- };
- export const UpdateUserDetails = (postData, callback) => dispatch => {
- axios({
- url: BaseApiUrl + "Users/UpdateUserDetails",
- method: "POST",
- data: postData,
- headers: {
- "Content-Type": "application/x-www-form-urlencoded"
- }
- }).then(
- resp => {
- if (resp.data.Success === true) {
- dispatch({
- type: SET_MESSAGE,
- payload: "Profile updated sucessfully."
- });
- dispatch({
- type: PROFILE_UPDATED_RESPONSE,
- payload: resp.data.Result
- });
- if (
- localStorage.IsProfileComplete === "False" &&
- resp.data.Result.IsProfileCompleted
- ) {
- localStorage.IsProfileComplete === "True";
- }
- callback && callback();
- } else {
- dispatch({
- type: SET_MESSAGE,
- payload:
- resp.data && !isEmpty(resp.data.Message)
- ? resp.data.Message
- : "Failed to update profile."
- });
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to connect to the server.."
- });
- }
- );
- };
- // export const UpdateInstructorDetails = postData => dispatch => {
- // axios({
- // url: BaseApiUrl + "Users/UpdateInstructorDetails",
- // method: "POST",
- // data: postData,
- // headers: {
- // "Content-Type": "application/x-www-form-urlencoded"
- // }
- // }).then(
- // resp => {
- // if (resp.data.Success === true) {
- // dispatch({
- // type: SET_MESSAGE,
- // payload: "Profile updated sucessfully."
- // });
- // dispatch({
- // type: PROFILE_UPDATED_RESPONSE,
- // payload: resp.data.Result
- // });
- // if((localStorage.IsProfileComplete==="False")&&(resp.data.Result.IsProfileCompleted)){
- // localStorage.IsProfileComplete==="True";
- // }
- // } else {
- // dispatch({
- // type: SET_MESSAGE,
- // payload:
- // resp.data && !isEmpty(resp.data.Message)
- // ? resp.data.Message
- // : "Failed to update profile."
- // });
- // }
- // },
- // err => {
- // dispatch({
- // type: SET_MESSAGE,
- // payload: "Failed to connect to the server.."
- // });
- // }
- // );
- // };
- export const MakeProfilePropsEmpty = contents => dispatch => {
- dispatch({
- type: MAKE_PROFILE_PROS_EMPTY,
- payload: contents
- });
- };
- export const verifyPhoneNumber = (code, callback) => dispatch => {
- axios({
- url: BaseApiUrl + "Users/VerifyUserPhoneNumber?code=" + code,
- method: "POST",
- headers: {
- "Content-Type": "application/json; charset=utf-8"
- }
- }).then(
- resp => {
- if (resp.data.Success) {
- dispatch({
- type: SET_MESSAGE,
- payload: resp.data.Message
- });
- callback && callback(resp.data.Result.PhoneNo);
- } else {
- dispatch({
- type: SET_MESSAGE,
- payload: resp.data.Message
- });
- //callback&&callback(resp.data)
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to verify phone."
- });
- }
- );
- };
- export const getUserGoals = () => dispatch => {
- axios.get(BaseApiUrl + "Users/GetUserGoalInfo").then(
- resp => {
- if (resp.data.Success === true) {
- dispatch({
- type: USER_GOALS_RETRIEVED,
- payload: {
- UserGoals: resp.data.Result.UserGoals,
- StudyPeriod: resp.data.Result.StudyPeriod,
- StudyUtilization: resp.data.Result.StudyUtilization,
- StudyAchievement: resp.data.Result.StudyAchievement
- }
- });
- } else {
- dispatch({
- type: SET_MESSAGE,
- payload: isEmpty(resp.data.Message)
- ? "Failed to load goals setting."
- : resp.data.Message
- });
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to connect to the server.."
- });
- }
- );
- };
- export const saveGoals = (postData, callback) => dispatch => {
- axios.post(BaseApiUrl + "Users/SaveUserGoals", postData).then(
- resp => {
- if (resp.data.Success === true) {
- dispatch({
- type: SET_MESSAGE,
- payload: "Goals saved"
- });
- dispatch({
- type: USER_GOALS_SAVED,
- payload: postData
- });
- callback && callback();
- } else {
- dispatch({
- type: SET_MESSAGE,
- payload:
- resp.data && !isEmpty(resp.data.Message)
- ? resp.data.Message
- : "Failed to save goals."
- });
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to connect to the server.."
- });
- }
- );
- };
- export const GetAuthorProfile = (_userid, callback) => dispatch => {
- axios
- .get(
- BaseApiUrl +
- "Users/GetOverallAuthorProfileDetail/?" +
- "&userid=" +
- _userid
- )
- .then(
- resp => {
- if (resp.data.Success === true) {
- dispatch({
- type: AUTHOR_PROFILE_LOAD,
- payload: {
- authorprofileData: resp.data.Result[0]
- }
- });
- callback && callback();
- } else {
- dispatch({
- type: SET_MESSAGE,
- payload: isEmpty(resp.data.Message)
- ? "Failed to load profile."
- : resp.data.Message
- });
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to connect to the server.."
- });
- }
- );
- };
- export const retrieveAuthorCourseList = (
- pageNumber = 1,
- pagesize = 5,
- userid,
- callBack
- ) => dispatch => {
- axios
- .get(BaseApiUrl + "Users/GetAuthorProfileCourses", {
- params: {
- CurrentPage: pageNumber,
- Take: pagesize,
- userID: userid
- }
- })
- .then(
- resp => {
- if (resp.data && resp.data.Success === true) {
- dispatch({
- type: AUTHOR_PROFILE_COURSE_LOAD,
- // payload: isEmpty(resp.data.Result.CourseMessages)
- // ? []
- // : resp.data.Result.CourseMessages
- payload: {
- Result: isEmpty(resp.data.Result) ? [] : resp.data.Result,
- CurrentPage: pageNumber
- }
- });
- callBack && callBack(resp.data.Result);
- } else {
- dispatch({
- type: SET_MESSAGE,
- payload:
- resp.data && !isEmpty(resp.data.Message)
- ? resp.data.Message
- : "Failed to retrieve course list."
- });
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to retrieve feed list."
- });
- }
- );
- };
- export const getAuthorProfileGrade = callback => dispatch => {
- axios.get(BaseApiUrl + "Users/GetAuthorProfileGrade").then(
- resp => {
- if (resp.data.Success === true) {
- callback && callback(resp.data.Result);
- } else {
- callback && callback([]);
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to connect to the server.."
- });
- }
- );
- };
- export const getAuthorProfileCourse = (userid, callback) => dispatch => {
- axios
- .get(BaseApiUrl + "Users/GetAuthorProfileCourse", {
- params: {
- userID: userid
- }
- })
- .then(
- resp => {
- if (resp.data.Success === true) {
- callback && callback(resp.data.Result);
- } else {
- callback && callback([]);
- }
- },
- err => {
- dispatch({
- type: SET_MESSAGE,
- payload: "Failed to connect to the server.."
- });
- }
- );
- };
- export const updateFollowStatus = (
- userID,
- isfollow,
- successCallBack,
- failureCallBack
- ) => dispatch => {
- var failureAction = message => {
- failureCallBack && failureCallBack();
- dispatch({
- type: SET_MESSAGE,
- payload: !isEmpty(message) ? message : "Failed to update follow user."
- });
- };
- axios({
- url:
- BaseApiUrl +
- "Users/ToggleFollowUnfollow?userID=" +
- userID +
- "&&follow=" +
- isfollow,
- method: "POST",
- headers: {
- "Content-Type": "application/json; charset=utf-8"
- }
- }).then(
- resp => {
- if (resp.data.Success) {
- dispatch({
- type: UPDATE_FOLLOW_STATE,
- IsFollowed: isfollow
- });
- successCallBack && successCallBack();
- } else {
- failureAction(resp.data.Message);
- }
- },
- err => {
- failureAction();
- }
- );
- };
- export const GetCourseCreatedGrades = callBack => dispatch => {
- axios.get(BaseApiUrl + "Course/GetCourseCreatedGrades").then(resp => {
- if (resp && resp.data && resp.data.Success) {
- callBack && callBack(resp.data.Result);
- }
- });
- };
- export const UpdateShowProfileIncompleteMsg = (
- postData,
- callback
- ) => dispatch => {
- axios
- .post(BaseApiUrl + "Users/UpdateShowProfileIncompleteMsg", postData)
- .then(
- resp => {
- if (resp.data.Success === true) {
- callback && callback({ error: false });
- }
- },
- err => {
- console.log("error", err);
- callback && callback({ error: err });
- }
- );
- };
- export const ChangeRole = (postData, callback) => dispatch => {
- axios
- .post(BaseApiUrl + "Users/ChangeRole", postData, {
- headers: {
- "Content-Type": "multipart/form-data"
- }
- })
- .then(
- resp => {
- if (resp.data.Success === true) {
- setMessageWithDispatch(resp.data.Message, dispatch);
- callback && callback({ error: false });
- }
- else if(resp.data.Success === false)
- {
- setMessageWithDispatch(resp.data.Message, dispatch);
- callback && callback({ error: true });
- }
- },
- err => {
- console.log("error", JSON.stringify(err.response));
- setMessageWithDispatch(
- isEmpty(err.response.data.Message)
- ? "Error"
- : err.response.data.Message,
- dispatch
- );
- callback && callback({ error: err });
- }
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement