reza added new proxy

master
Reza_ashrafi 3 years ago
parent dd3e29fcb9
commit f414876aae
  1. 19
      src/Redux/actions/blog.js
  2. 36
      src/Redux/actions/chat.js
  3. 4
      src/Redux/actions/index.js
  4. 44
      src/Redux/actions/user.js
  5. 120
      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. 39
      src/views/Auth/Login/index.js
  11. 4
      src/views/ChatList/index.js
  12. 6
      src/views/ChatRoom/Body/index.js
  13. 36
      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';
export const list =
import proxy from "../proxy";
const chat = {
list:
(data = {}) =>
async (dispatch) =>
(await proxy.get('chat/list', data)).dispatch(dispatch);
export const info =
await proxy.get("chat/list", data, { dispatch }),
info:
(data = {}) =>
async (dispatch) =>
(await proxy.get('chat/info', data)).dispatch(dispatch);
export const bio =
await proxy.get("chat/info", data, { dispatch }),
bio:
(data = {}) =>
async (dispatch) =>
(await proxy.get('chat/bio', data)).dispatch(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
export { default as chat } from './chat.js';
export { default as message } from './message.js';
export { default as public } from './public.js';
// export { default as message } from './message.js';
// export { default as public } from './public.js';
export { default as user } from './user.js';

@ -1,9 +1,37 @@
import proxy from '../proxy';
export const login =
(data = {}) =>
async (dispatch) =>
(await proxy.login(data)).dispatch(dispatch);
export const logout =
(data = {}) =>
async (dispatch) =>
(await proxy.logout(data)).dispatch(dispatch);
const user = {
otp: (data, history) => async (dispatch) =>
await proxy.login('public/sendOTP', data, { history, dispatch }),
otp_login: (data, history) => async (dispatch) =>
await proxy.login('user/otp/login', data, { history, dispatch }),
register: (data, history) => async (dispatch) =>
await proxy.login('user/register', data, { history, 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 { toast } from 'react-toastify';
const baseURL = 'https://chatstory.ir/api/v1'; //'https://chatstory.ir/api/v1';
const token = '';
const loginURL = 'user/otp/login';
const logoutURL = 'user/logout';
window.baseURL = baseURL;
let { baseUrl, apiKey } = ApiConfig;
baseUrl = baseUrl + '/';
const baseUrl2 = 'https://dnvn.ir/api/v1';
const Axios = axios.create({
withCredentials: true,
validateStatus: null,
baseURL,
baseURL: baseUrl,
});
class dispatch {}
class Proxy {
get = (url, params, opt = {}) => this.check(url, () => Axios.get(url, { params, ...opt }));
post = (url, params, opt = {}) => this.check(url, () => Axios.post(url, params, opt));
put = (url, params, opt = {}) => this.check(url, () => Axios.put(url, params, opt));
delete = (url, params, opt = {}) => this.check(url, () => Axios.delete(url, params, opt));
result = (url, data) => ({
...data,
dispatch: (dispatch) => {
dispatch({ type: url, data });
return data;
},
const Axios2 = axios.create({
withCredentials: true,
validateStatus: null,
baseURL: baseUrl2,
});
check = async (url, fetch) => {
class Proxy {
get = async (url, params, opt = {}) =>
await this.check(
url,
opt,
async () => await Axios.get(url, { params, ...opt })
);
get2 = async (url, params, opt = {}) =>
await this.check2(
url,
opt,
async () => await Axios2.get(url, { params, ...opt })
);
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();
switch (response.status) {
case 200:
return this.result(url, response.data.data);
dispatch({ type: url, data: response.data.data });
return response.data.data;
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;
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;
};
refresh = async () => {
let refresh = localStorage.getItem('refresh');
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;
};
login = async (data, opt = { headers: { Authorization: `Bearer ${token}` } }) => {
const login = await this.post(loginURL, data, opt);
if (!login || !login.refreshToken) return this.result('login', false);
login = async (url, params, { dispatch }) =>
this.post(url, params, {
dispatch: (obj) => {
let login = obj.data;
if (!login || !login.refreshToken) return false;
localStorage.setItem('refresh', login.refreshToken);
delete login.refreshToken;
delete login.accessToken;
localStorage.setItem('userData', JSON.stringify(login));
window.location = "/";
if (data != {}) window.router.setState({ islogin: true });
return this.result('login', login);
};
logout = async () => {
this.post(logoutURL);
dispatch(obj);
},
});
logout = async (url, params, { dispatch }) => {
this.post(url, params, {
dispatch: (obj) => {
localStorage.removeItem('refresh');
localStorage.removeItem('userData');
window.router.setState({ islogin: false });
return this.result('logout', {});
dispatch(obj);
},
});
};
status = () => {
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';
const initialState = {
isLogin: proxy.status(),
status: proxy.status(),
loading: false,
error: null,
list: null,
domains: [],
mothers: [],
};
export default function user(state = initialState, action) {
let { type, data } = action;
switch (type) {
case 'login':
return { ...state, ...proxy.status(), islogin: proxy.status(), ...data };
case 'logout':
return { ...state, islogin: proxy.status() };
case 'user/login':
case 'user/register':
case 'user/otp/login':
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:
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">
<h1>دانوین</h1>
<p>
یک کد تائیدیه به شماره <span>09123190615</span> ارسال شد <br />
یک کد تائیدیه به شماره <span>{this.props.parent.state.cellphone}</span> ارسال شد <br />
آن را در قسمت زیر وارد کنید.
</p>
</div>

@ -4,53 +4,46 @@ import Cellphone from "./Cellphone/index";
import Code from "./Code/index";
import Splash from "../Splash/index";
import { otp } from '../../../Redux/actions/public';
import { login } from '../../../Redux/actions/user';
import { connect } from 'react-redux';
import { user } from "../../../Redux/actions";
import { connect } from "react-redux";
class Login extends Component {
constructor(props) {
super(props);
this.state = {
page: 0,
splash : true,
splash: false,
};
}
async componentDidUpdate() {
const { cellphone, otp, page } = this.state;
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 = () => {
const { cellphone } = this.state;
this.props.otp({ cellphone });
}
};
render() {
return (
<>
{
this.state.page === 0 ?
( !this.state.splash ? <Cellphone parent={this} /> : null) :
{this.state.page === 0 ? (
!this.state.splash ? (
<Cellphone 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 {Link} from 'react-router-dom';
import { list } from '../../Redux/actions/chat';
import { chat } from '../../Redux/actions';
import { connect } from 'react-redux';
import ChatIcon from '@material-ui/icons/Chat';
import Chat from './Chat/index';
@ -70,6 +70,6 @@ export default connect(
(state) => ({
chat_list: state.chat.list || [],
}),
{ list }
{ list : chat.list }
)(ChatList);

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

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