update for offstage logout, minor updates

This commit is contained in:
merelendor 2022-09-12 22:54:12 +03:00
parent 094be65a16
commit 963bd4cdb0
12 changed files with 85 additions and 111 deletions

View File

@ -156,9 +156,13 @@ export const logout = ({ dispatch, redirect = true }) =>
dispatch({ type: actionTypes.AUTH, data: { logged: false, observer: false } });
dispatch({ type: actionTypes.USER, data: {} });
dispatch({ type: actionTypes.COMPANY, data: {} });
dispatch({ type: actionTypes.CONTRACTS_INFO_RESET, data: {} });
dispatch({ type: actionTypes.EVENTS_RESET, data: {} });
dispatch({ type: actionTypes.SUPPORT_RESET, data: {} });
dispatch({ type: actionTypes.CONTRACTS_INFO_RESET, data: {} });
dispatch({ type: actionTypes.CONTRACT_EVENTS_RESET, data: {} });
dispatch({ type: actionTypes.CONTRACT_FINES_RESET, data: {} });
window.store.__persistor.purge();
resolve();
if(redirect)

View File

@ -24,10 +24,12 @@ if(process.browser)
export const getEvents = ({ dispatch, type, contract }) =>
{
console.log("getEvents", `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/events`);
console.log("ACTION", "getEvents()");
return new Promise((resolve, reject) =>
{
console.log("global.store.getState()", global.store.getState());
if(global.store.getState().events.list === undefined)
{
axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/events`, {}, {

View File

@ -59,7 +59,7 @@ export const setAppealsRead = ({ dispatch, appeals }) =>
export const getAppeals = ({ dispatch }) =>
{
console.log("ACTION", "support", "getAppeals", `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/support/appeals`);
console.log("ACTION", "support", "getAppeals()", `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/support/appeals`);
return new Promise((resolve, reject) =>
{
@ -68,12 +68,7 @@ export const getAppeals = ({ dispatch }) =>
})
.then((response) =>
{
console.log("getEvents", "response", response.data);
const events = response.data;
const filtered_events = [];
console.log("events");
console.log(events);
console.log("ACTION", "support", "getAppeals()", "response", response.data);
dispatch({ type: actionTypes.SUPPORT_APPEALS, data: { appeals: { list: response.data.appeals, new: response.data.new, } } });
resolve();

View File

@ -21,8 +21,7 @@ export default async function handler(req, res)
var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT);
var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true });
console.log("client_jwt_decoded");
console.log(client_jwt_decoded);
console.log("API", "events", "client_jwt_decoded", client_jwt_decoded);
try
{

View File

@ -8,25 +8,17 @@ import { cors } from '../../../lib/cors';
export default async function handler(req, res)
{
console.log("API\n\n\n\n\n\n\n");
console.log("API", "file", "image");
await cors(req, res);
if(req.headers.cookie !== undefined)
{
console.log("api 1");
const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : "");
if(cookies.jwt !== undefined && cookies.jwt !== null)
{
console.log("api 2");
var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT);
var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true });
console.log("api 3");
console.log("API", "file", "image", "/file/GetImage", "req.query.id", req.query.id);
await axios.get(`${ process.env.CRM_API_HOST }/file/GetImage`, {
params: { id: req.query.id },
responseType: 'arraybuffer',
@ -38,13 +30,8 @@ export default async function handler(req, res)
{
try
{
console.log("crm_response.data");
console.log(crm_response.data);
const base64image = `data:${ crm_response['headers']['content-type'] };base64,${ Buffer.from(crm_response.data, 'binary').toString('base64') }`;
console.log("base64image");
console.log(base64image);
res.status(200).send(base64image);
}
catch(e)
@ -66,6 +53,6 @@ export default async function handler(req, res)
}
else
{
console.log("WTF?!?!?!!?");
res.status(403);
}
}

View File

@ -33,10 +33,12 @@ class Header extends React.Component
componentDidMount()
{
const { dispatch } = this.props;
console.log("Header", "CDM");
getEvents({ dispatch: this.props.dispatch });
getEvents({ dispatch });
console.log("Header", "CDM", "222222");
getAppeals({ dispatch: this.props.dispatch });
getAppeals({ dispatch });
}
componentDidUpdate(prevProps, prevState)

View File

@ -12,7 +12,7 @@ export default class MainHeader extends React.Component
{
const { logo_url } = this.props;
console.log("Header", "this.props", this.props);
console.log("MainHeader", "this.props", this.props);
return (
<header>
<div className="container">

View File

@ -323,6 +323,18 @@ class SumSelector extends React.Component
}
}
_handle_onMin = () =>
{
const { min } = this.state;
this.setState({ value: min });
}
_handle_onMax = () =>
{
const { max } = this.state;
this.setState({ value: max });
}
_handle_onMobileHelp = () =>
{
if(window.innerWidth < 768)
@ -341,8 +353,8 @@ class SumSelector extends React.Component
<label style={ option.disable ? { opacity: 0.5 } : {} }>Изменить сумму платежа</label>
<div className="input_with_notes" style={ option.disable ? { opacity: 0.5 } : {} }>
<input type="number" placeholder="Укажите сумму" defaultValue={ value } disabled={ option.disable ? true : false } onChange={ this._handle_onChange }/>
<span>от { numeral(min).format(' ., ') }&nbsp;</span>
<span>до { numeral(max).format(' ., ') }&nbsp;</span>
<span className="interactive" style={{ textDecoration: "underline" }} onClick={ this._handle_onMin }>от { numeral(min).format(' ., ') }&nbsp;</span>
<span className="interactive" style={{ textDecoration: "underline" }} onClick={ this._handle_onMax }>до { numeral(max).format(' ., ') }&nbsp;</span>
</div>
{ option.information !== undefined && option.information !== null && (
<div className="help_tooltip">
@ -420,6 +432,18 @@ class InsurancePriceSelector extends React.Component
//}
}
_handle_onMin = () =>
{
const { min } = this.state;
this.setState({ value: min });
}
_handle_onMax = () =>
{
const { max } = this.state;
this.setState({ value: max });
}
_handle_onMobileHelp = () =>
{
if(window.innerWidth < 768)
@ -442,8 +466,8 @@ class InsurancePriceSelector extends React.Component
) : (
<>
<input type="number" placeholder="Укажите сумму" defaultValue={ value } disabled={ option.disable ? true : false } onChange={ this._handle_onChange }/>
<span>от { numeral(min).format(' ., ') }&nbsp;</span>
<span>до { numeral(max).format(' ., ') }&nbsp;</span>
<span className="interactive" style={{ textDecoration: "underline" }} onClick={ this._handle_onMin }>от { numeral(min).format(' ., ') }&nbsp;</span>
<span className="interactive" style={{ textDecoration: "underline" }} onClick={ this._handle_onMax }>до { numeral(max).format(' ., ') }&nbsp;</span>
</>
) }
</div>

View File

@ -14,6 +14,7 @@ class InnerMenu extends React.Component
loaded: false,
loading: true,
menuOpened: false,
events_loaded: false,
contracts_info: {},
contract_events: {},
contract_fines: {},
@ -23,6 +24,7 @@ class InnerMenu extends React.Component
static getDerivedStateFromProps(nextProps, prevState)
{
return {
events_loaded: nextProps.events_loaded,
contracts_info: nextProps.contracts_info,
contract_events: nextProps.contract_events,
contract_fines: nextProps.contract_fines,
@ -33,20 +35,10 @@ class InnerMenu extends React.Component
{
console.log("Contact", "InnerMenu", "componentDidMount()");
const { loaded, loading, contracts_info, contract_events, contract_fines } = this.state;
const { loaded, loading, events_loaded, contracts_info, contract_events, contract_fines } = this.state;
console.log("CDM", "\n\n");
console.log("CDM", "contracts_info", contracts_info);
console.log("CDM", "!".repeat(10));
console.log("CDM", "contract_events", contract_events);
console.log("CDM", "!".repeat(10));
console.log("CDM", "contract_fines", contract_fines);
console.log("CDM", "!".repeat(10));
if(!loaded &&
contracts_info !== undefined && Object.keys(contracts_info).length > 0 &&
contract_events !== undefined && Object.keys(contract_events).length > 0 &&
contract_fines !== undefined && Object.keys(contract_fines).length > 0
if(!loaded && events_loaded &&
contracts_info !== undefined && Object.keys(contracts_info).length > 0
) {
this.setState({ loaded: true }, () =>
{
@ -57,21 +49,10 @@ class InnerMenu extends React.Component
componentDidUpdate(prevProps, prevState)
{
const { loaded, contracts_info, contract_events, contract_fines } = this.state;
const { loaded, events_loaded, contracts_info, contract_events, contract_fines } = this.state;
console.log("CDU", "\n\n");
console.log("CDU", "contracts_info", contracts_info);
console.log("CDU", "?".repeat(10));
console.log("CDU", "contract_events", contract_events);
console.log("CDU", "?".repeat(10));
console.log("CDU", "contract_fines", contract_fines);
console.log("CDU", "?".repeat(10));
if(!loaded &&
contracts_info !== undefined && Object.keys(contracts_info).length > 0 &&
contract_events !== undefined && Object.keys(contract_events).length > 0 &&
contract_fines !== undefined && Object.keys(contract_fines).length > 0
) {
if(!loaded && events_loaded && contracts_info !== undefined && Object.keys(contracts_info).length > 0)
{
this.setState({ loaded: true }, () =>
{
this._loadMenu();
@ -89,56 +70,46 @@ class InnerMenu extends React.Component
Promise.all([
new Promise((resolve) =>
{
console.log(11111);
if(contracts_info[ number ] === undefined)
{
console.log(10);
getContractInfo({ dispatch, number })
.then(() => { console.log(11); resolve(); })
.catch(() => { console.log(12); resolve(); });
}
else
{
console.log(13);
resolve();
}
}),
new Promise((resolve) =>
{
console.log(22222);
if(contract_events[ number ] === undefined)
{
console.log(20);
getContractEvents({ dispatch, contract: number })
.then(() => { console.log(21); resolve(); })
.catch(() => { console.log(22); resolve(); });
}
else
{
console.log(23);
resolve();
}
}),
new Promise((resolve) =>
{
console.log(33333);
if(contract_fines[ number ] === undefined)
{
console.log(30);
getContractFines({ dispatch, contract: number })
.then(() => { console.log(31); resolve(); })
.catch(() => { console.log(32); resolve(); });
}
else
{
console.log(33);
resolve();
}
}),
])
.then(() =>
{
console.log("******************************");
let l = 0;
let m = 0;
const menu = [ "payments", "change", "services", "agreement", "documents", "materials", "events", "fines" ];
@ -151,39 +122,24 @@ class InnerMenu extends React.Component
}
}
//setTimeout(() =>
//{
this.setState({ loading: false }, () =>
this.setState({ loading: false }, () =>
{
if(this.menuRef.current !== null)
{
for(let i = 0; i < m; i++)
{
if(this.menuRef.current.children[i] !== undefined)
{
l = l + this.menuRef.current.children[i].getBoundingClientRect().width;
}
}
if(this.menuRef.current !== null)
{
console.log("-".repeat(30));
console.log(this.menuRef.current);
console.log("-".repeat(30));
for(let i = 0; i < m; i++)
{
//console.log("-----", this.menuRef.current.children[i]);
if(this.menuRef.current.children[i] !== undefined)
{
console.log("this.menuRef.current.children[i]", this.menuRef.current.children[i]);
console.log(".".repeat(30));
l = l + this.menuRef.current.children[i].getBoundingClientRect().width;
console.log("W", this.menuRef.current.children[i].getBoundingClientRect().width, l);
}
}
//setTimeout(() =>
//{
if(this.menuRef.current !== null)
{
this.menuRef.current.scrollLeft = l - 50;
}
//}, 10);
this.menuRef.current.scrollLeft = l - 50;
}
});
//}, 50);
}
});
});
}
@ -301,6 +257,7 @@ class InnerMenu extends React.Component
function mapStateToProps(state, ownProps)
{
return {
events_loaded: state.events.loaded,
contracts_info: state.contracts_info,
contract_events: state.contract_events,
contract_fines: state.contract_fines,

View File

@ -12,7 +12,7 @@ import Footer from './components/Footer';
import MainHeader from "./components/MainHeader";
import FormRequest from "./components/FormRequest";
import { sendOffstageToken } from '../actions';
import { logout, sendOffstageToken } from '../actions';
class OffstagePage extends React.Component
{
@ -32,14 +32,20 @@ class OffstagePage extends React.Component
componentDidMount()
{
sendOffstageToken({ dispatch: this.props.dispatch, token: this.props.token })
const { dispatch, token } = this.props;
logout({ dispatch, redirect: false })
.then(() =>
{
this.setState({ error: false });
})
.catch(() =>
{
this.setState({ error: true });
sendOffstageToken({ dispatch, token })
.then(() =>
{
this.setState({ error: false });
})
.catch(() =>
{
this.setState({ error: true });
});
});
}

View File

@ -26,11 +26,9 @@ const eventsReducer = (state = initialState.events, action) =>
case actionTypes.EVENTS_RESET:
{
return {
themes: null,
searched: null,
appeals: { list: null, new: 0 },
appeal: null,
request: null,
loaded: false,
list: undefined,
filtered: undefined,
};
}