reza added new proxy

master
Reza_ashrafi 3 years ago
parent dd3e29fcb9
commit f414876aae
  1. 19
      src/Redux/actions/blog.js
  2. 48
      src/Redux/actions/chat.js
  3. 4
      src/Redux/actions/index.js
  4. 44
      src/Redux/actions/user.js
  5. 130
      src/Redux/proxy.js
  6. 25
      src/Redux/reducers/blog.js
  7. 31
      src/Redux/reducers/user.js
  8. 9
      src/constants/defaultValues.js
  9. 2
      src/views/Auth/Login/Code/index.js
  10. 45
      src/views/Auth/Login/index.js
  11. 4
      src/views/ChatList/index.js
  12. 6
      src/views/ChatRoom/Body/index.js
  13. 54
      src/views/QR/VideoBox/index.js

@ -0,0 +1,19 @@
import proxy from '../proxy';
const blog = {
list: (data = {}) => async (dispatch) =>
await proxy.get('blog/list', data, { dispatch }),
update: (data = {}, data2 = {}) => async (dispatch) => {
await proxy.put('blog/update', data);
await proxy.get('blog/list', data2, { dispatch });
},
add: (data = {}, data2 = {}) => async (dispatch) => {
await proxy.post('blog/add', data);
await proxy.get('blog/list', data2, { dispatch });
},
del: (data = {}, data2 = {}) => async (dispatch) => {
await proxy.delete('blog/delete', data);
await proxy.get('blog/list', data2, { dispatch });
},
};
export default blog;

@ -1,13 +1,35 @@
import proxy from '../proxy'; import proxy from "../proxy";
export const list = const chat = {
(data = {}) => list:
async (dispatch) => (data = {}) =>
(await proxy.get('chat/list', data)).dispatch(dispatch); async (dispatch) =>
export const info = await proxy.get("chat/list", data, { dispatch }),
(data = {}) => info:
async (dispatch) => (data = {}) =>
(await proxy.get('chat/info', data)).dispatch(dispatch); async (dispatch) =>
export const bio = await proxy.get("chat/info", data, { dispatch }),
(data = {}) => bio:
async (dispatch) => (data = {}) =>
(await proxy.get('chat/bio', data)).dispatch(dispatch); async (dispatch) =>
await proxy.get("chat/bio", data, { dispatch }),
update:
(data = {}, data2 = {}) =>
async (dispatch) => {
await proxy.put("blog/update", data);
await proxy.get("blog/list", data2, { dispatch });
},
add:
(data = {}, data2 = {}) =>
async (dispatch) => {
await proxy.post("blog/add", data);
await proxy.get("blog/list", data2, { dispatch });
},
del:
(data = {}, data2 = {}) =>
async (dispatch) => {
await proxy.delete("blog/delete", data);
await proxy.get("blog/list", data2, { dispatch });
},
};
export default chat;

@ -1,7 +1,7 @@
// @create-index // @create-index
export { default as chat } from './chat.js'; export { default as chat } from './chat.js';
export { default as message } from './message.js'; // export { default as message } from './message.js';
export { default as public } from './public.js'; // export { default as public } from './public.js';
export { default as user } from './user.js'; export { default as user } from './user.js';

@ -1,9 +1,37 @@
import proxy from '../proxy'; import proxy from '../proxy';
export const login = const user = {
(data = {}) => otp: (data, history) => async (dispatch) =>
async (dispatch) => await proxy.login('public/sendOTP', data, { history, dispatch }),
(await proxy.login(data)).dispatch(dispatch); otp_login: (data, history) => async (dispatch) =>
export const logout = await proxy.login('user/otp/login', data, { history, dispatch }),
(data = {}) => register: (data, history) => async (dispatch) =>
async (dispatch) => await proxy.login('user/register', data, { history, dispatch }),
(await proxy.logout(data)).dispatch(dispatch); switchRole: (data, history) => async (dispatch) =>
await proxy.login('user/switchRole', data, { history, dispatch }),
logout: (data, history) => async (dispatch) =>
await proxy.logout('user/logout', data, { history, dispatch }),
getUserRole: (data) => async (dispatch) =>
await proxy.get('user/getUserRole', data, { dispatch }),
list: (data = {}) => async (dispatch) =>
await proxy.get('user/list', data, { dispatch }),
domains: (data = {}) => async (dispatch) =>
await proxy.get('user/domains', data, { dispatch }),
getmothers: (data = {}) => async (dispatch) =>
await proxy.get2('mothers/list', data, {
dispatch,
}),
update: (data = {}, data2 = {}) => async (dispatch) => {
await proxy.put('user/update', data);
await proxy.get('user/list', data2, { dispatch });
},
add: (data = {}, data2 = {}) => async (dispatch) => {
await proxy.post('user/add', data);
await proxy.get('user/list', data2, { dispatch });
},
del: (data = {}, data2 = {}) => async (dispatch) => {
await proxy.delete('user/delete', data);
await proxy.get('user/list', data2, { dispatch });
},
};
export default user;

@ -1,63 +1,113 @@
import { ApiConfig } from './../constants/defaultValues';
import axios from 'axios'; import axios from 'axios';
import { toast } from 'react-toastify';
const baseURL = 'https://chatstory.ir/api/v1'; //'https://chatstory.ir/api/v1'; let { baseUrl, apiKey } = ApiConfig;
const token = ''; baseUrl = baseUrl + '/';
const loginURL = 'user/otp/login'; const baseUrl2 = 'https://dnvn.ir/api/v1';
const logoutURL = 'user/logout';
window.baseURL = baseURL;
const Axios = axios.create({ const Axios = axios.create({
withCredentials: true, withCredentials: true,
validateStatus: null, validateStatus: null,
baseURL, baseURL: baseUrl,
});
const Axios2 = axios.create({
withCredentials: true,
validateStatus: null,
baseURL: baseUrl2,
}); });
class dispatch {}
class Proxy { class Proxy {
get = (url, params, opt = {}) => this.check(url, () => Axios.get(url, { params, ...opt })); get = async (url, params, opt = {}) =>
post = (url, params, opt = {}) => this.check(url, () => Axios.post(url, params, opt)); await this.check(
put = (url, params, opt = {}) => this.check(url, () => Axios.put(url, params, opt)); url,
delete = (url, params, opt = {}) => this.check(url, () => Axios.delete(url, params, opt)); opt,
result = (url, data) => ({ async () => await Axios.get(url, { params, ...opt })
...data, );
dispatch: (dispatch) => { get2 = async (url, params, opt = {}) =>
dispatch({ type: url, data }); await this.check2(
return data; url,
}, opt,
}); async () => await Axios2.get(url, { params, ...opt })
check = async (url, fetch) => { );
post = async (url, params, opt = {}) =>
await this.check(url, opt, async () => await Axios.post(url, params, opt));
put = async (url, params, opt = {}) =>
await this.check(url, opt, async () => await Axios.put(url, params, opt));
delete = async (url, params, opt = {}) => {
await this.check(
url,
opt,
async () => await Axios.delete(url, { ...opt, data: params })
);
};
check = async (url, { dispatch }, fetch) => {
dispatch = dispatch || (() => {});
dispatch({ type: 'loading' });
let response = await fetch(); let response = await fetch();
switch (response.status) { switch (response.status) {
case 200: case 200:
return this.result(url, response.data.data); dispatch({ type: url, data: response.data.data });
return response.data.data;
case 401: case 401:
if (await this.refresh()) return this.result(url, (await fetch()).data.data); if (await this.refresh()) {
let response = await fetch();
dispatch({ type: url, data: response.data.data });
return response.data.data;
}
break; break;
default: default:
toast.error(response.data.message); dispatch({ type: 'error', data: response.data });
}
return false;
};
check2 = async (url, { dispatch }, fetch) => {
dispatch({ type: 'loading' });
let response = await fetch();
switch (response.status) {
case 200:
dispatch({ type: url, data: response.data });
return response.data;
case 401:
if (await this.refresh()) {
let response = await fetch();
dispatch({ type: url, data: response.data });
return response.data;
}
break;
default:
dispatch({ type: 'error', data: response.data });
} }
return false; return false;
}; };
refresh = async () => { refresh = async () => {
let refresh = localStorage.getItem('refresh'); let refresh = localStorage.getItem('refresh');
if (!refresh) window.location.href = '/'; if (!refresh) window.location.href = '/';
let login = await this.login({}, { headers: { Authorization: `Bearer ${refresh}` } }); let login = await this.login(
{},
{ headers: { Authorization: `Bearer ${refresh}` } }
);
return login ? true : false; return login ? true : false;
}; };
login = async (data, opt = { headers: { Authorization: `Bearer ${token}` } }) => { login = async (url, params, { dispatch }) =>
const login = await this.post(loginURL, data, opt); this.post(url, params, {
if (!login || !login.refreshToken) return this.result('login', false); dispatch: (obj) => {
localStorage.setItem('refresh', login.refreshToken); let login = obj.data;
delete login.refreshToken; if (!login || !login.refreshToken) return false;
localStorage.setItem('userData', JSON.stringify(login)); localStorage.setItem('refresh', login.refreshToken);
window.location = "/"; delete login.refreshToken;
if (data != {}) window.router.setState({ islogin: true }); delete login.accessToken;
return this.result('login', login); localStorage.setItem('userData', JSON.stringify(login));
}; dispatch(obj);
logout = async () => { },
this.post(logoutURL); });
localStorage.removeItem('refresh');
localStorage.removeItem('userData'); logout = async (url, params, { dispatch }) => {
window.router.setState({ islogin: false }); this.post(url, params, {
return this.result('logout', {}); dispatch: (obj) => {
localStorage.removeItem('refresh');
localStorage.removeItem('userData');
dispatch(obj);
},
});
}; };
status = () => { status = () => {
let refresh = localStorage.getItem('refresh'); let refresh = localStorage.getItem('refresh');

@ -0,0 +1,25 @@
const initialState = {
loading: false,
error: null,
list: [],
};
export default function user(state = initialState, action) {
let { type, data } = action;
switch (type) {
case 'blog/list':
return { ...state, loading: false, list: data, error: null };
case 'blog/update':
return { ...state, loading: false, error: null };
case 'blog/add':
return { ...state, loading: false, error: null };
case 'blog/delete':
return { ...state, loading: false, error: null };
/////////////
case 'loading':
return { ...state, loading: true };
case 'error':
return { ...state, loading: false, error: data.message };
default:
return state;
}
}

@ -1,14 +1,35 @@
import proxy from '../proxy'; import proxy from '../proxy';
const initialState = { const initialState = {
isLogin: proxy.status(), status: proxy.status(),
loading: false,
error: null,
list: null,
domains: [],
mothers: [],
}; };
export default function user(state = initialState, action) { export default function user(state = initialState, action) {
let { type, data } = action; let { type, data } = action;
switch (type) { switch (type) {
case 'login': case 'user/login':
return { ...state, ...proxy.status(), islogin: proxy.status(), ...data }; case 'user/register':
case 'logout': case 'user/otp/login':
return { ...state, islogin: proxy.status() }; case 'user/switchRole':
return { ...state, loading: false, status: data, error: null };
case 'user/logout':
return { ...state, loading: false, status: proxy.status(), error: null };
case 'user/getUserRole':
return { ...state, loading: false, userRoles: data, error: null };
case 'user/list':
return { ...state, loading: false, list: data, error: null };
case 'user/domains':
return { ...state, loading: false, domains: data, error: null };
case 'mothers/list':
return { ...state, loading: false, mothers: data, error: null };
/////////////
case 'loading':
return { ...state, loading: true };
case 'error':
return { ...state, loading: false, error: data.message };
default: default:
return state; return state;
} }

@ -0,0 +1,9 @@
export const ApiConfig = {
apiKey: 'AIzaSyBBksq-Asxq2M4Ot-75X19IyrEYJqNBPcg',
authDomain: 'dnvn.ir',
baseUrl: 'https://dnvn.ir/api/v1',
//baseUrl: 'http://localhost:3030/api/v1',
loginURL: 'user/login',
otploginURL: 'user/otp/login',
logoutURL: 'user/logout',
};

@ -210,7 +210,7 @@ export default class Code extends Component {
<div style={{ maxHeight: 60 }} className="d-flex flex-column mb-3"> <div style={{ maxHeight: 60 }} className="d-flex flex-column mb-3">
<h1>دانوین</h1> <h1>دانوین</h1>
<p> <p>
یک کد تائیدیه به شماره <span>09123190615</span> ارسال شد <br /> یک کد تائیدیه به شماره <span>{this.props.parent.state.cellphone}</span> ارسال شد <br />
آن را در قسمت زیر وارد کنید. آن را در قسمت زیر وارد کنید.
</p> </p>
</div> </div>

@ -4,53 +4,46 @@ import Cellphone from "./Cellphone/index";
import Code from "./Code/index"; import Code from "./Code/index";
import Splash from "../Splash/index"; import Splash from "../Splash/index";
import { otp } from '../../../Redux/actions/public'; import { user } from "../../../Redux/actions";
import { login } from '../../../Redux/actions/user'; import { connect } from "react-redux";
import { connect } from 'react-redux';
class Login extends Component { class Login extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
page: 0, page: 0,
splash : true, splash: false,
}; };
} }
async componentDidUpdate() { async componentDidUpdate() {
const { cellphone, otp, page } = this.state; const { cellphone, otp, page } = this.state;
if (cellphone && !otp) this.props.otp({ cellphone }); if (cellphone && !otp) this.props.otp({ cellphone });
if (page && cellphone && otp) this.props.login({ cellphone, otp }); if (page && cellphone && otp) this.props.otp_login({ cellphone : cellphone, otp: Number(otp) });
} }
componentDidMount() {
setTimeout(() =>{
this.setState({
splash: false,
})
},6000);
}
resend = () => { resend = () => {
const {cellphone} = this.state; const { cellphone } = this.state;
this.props.otp({cellphone}); this.props.otp({ cellphone });
} };
render() { render() {
return ( return (
<> <>
{ {this.state.page === 0 ? (
this.state.page === 0 ? !this.state.splash ? (
( !this.state.splash ? <Cellphone parent={this} /> : null) : <Cellphone parent={this} />
<Code parent={this} /> ) : null
} ) : (
{ <Code parent={this} />
this.state.splash ? <Splash /> : null )}
} {this.state.splash ? <Splash /> : null}
</> </>
); );
} }
} }
export default connect((state) => ({ isLogin: state.user.isLogin }), { otp, login })(Login); export default connect((state) => ({ isLogin: state.user.isLogin }), {
otp: user.otp,
otp_login: user.otp_login,
})(Login);

@ -1,6 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import {Link} from 'react-router-dom'; import {Link} from 'react-router-dom';
import { list } from '../../Redux/actions/chat'; import { chat } from '../../Redux/actions';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import ChatIcon from '@material-ui/icons/Chat'; import ChatIcon from '@material-ui/icons/Chat';
import Chat from './Chat/index'; import Chat from './Chat/index';
@ -70,6 +70,6 @@ export default connect(
(state) => ({ (state) => ({
chat_list: state.chat.list || [], chat_list: state.chat.list || [],
}), }),
{ list } { list : chat.list }
)(ChatList); )(ChatList);

@ -6,8 +6,8 @@ import { RecordState } from "audio-react-recorder";
import ReactPlayer from "react-player"; import ReactPlayer from "react-player";
import ReactAudioPlayer from "react-audio-player"; import ReactAudioPlayer from "react-audio-player";
import { ToastContainer } from "react-toastify"; import { ToastContainer } from "react-toastify";
import { list, send, sendKeys } from "../../../Redux/actions/message"; // import { list, send, sendKeys } from "../../../Redux/actions/message";
import { info, bio } from "../../../Redux/actions/chat"; import { chat } from "../../../Redux/actions";
import { connect } from "react-redux"; import { connect } from "react-redux";
import Emoji from "./Emoji/index"; import Emoji from "./Emoji/index";
@ -655,5 +655,5 @@ export default connect(
last: state.message.list.slice(-1)[0] || {}, last: state.message.list.slice(-1)[0] || {},
}; };
}, },
{ list, send, sendKeys, info, bio } { info : chat.info , bio : chat.bio }
)(List); )(List);

@ -1,27 +1,33 @@
import React from 'react'; import React from "react";
import {VideoCard} from 'material-ui-player'; import { VideoCard } from "material-ui-player";
import ReactVideoJsPlayer from './React-video-js-player/index'; import ReactVideoJsPlayer from "./React-video-js-player/index";
import './index.scss'; import "./index.scss";
export default function VideoBox(props) {
export default function VideoBox(props){ return (
return( <>
<> {window.innerWidth > 1000 ? (
{ <div className="video-box d-flex flex-column" id="video">
window.innerWidth > 1000 ? <h2
<div className="video-box d-flex flex-column" id="video"> style={{ fontSize: props.fontSize.desktop.content.h2 }}
<h2 style={{fontSize: props.fontSize.desktop.content.h2 }} className="d-flex align-items-center"><span></span>{props.data.title}</h2> className="d-flex align-items-center"
<ReactVideoJsPlayer /> >
</div> : null <span></span>
} {props.data.title}
{ </h2>
window.innerWidth < 1000 ? <ReactVideoJsPlayer />
<div className="mobile-video-box d-flex flex-column" id="video"> </div>
<h2 className="d-flex align-items-center"><span></span>{props.data.title}</h2> ) : null}
<ReactVideoJsPlayer /> {window.innerWidth < 1000 ? (
</div> : null <div className="mobile-video-box d-flex flex-column" id="video">
} <h2 className="d-flex align-items-center">
</> <span></span>
); {props.data.title}
</h2>
<ReactVideoJsPlayer />
</div>
) : null}
</>
);
} }
Loading…
Cancel
Save