diff --git a/src/actions/helpers.ts b/src/actions/helpers.ts index 6522b69..812980d 100644 --- a/src/actions/helpers.ts +++ b/src/actions/helpers.ts @@ -23,22 +23,22 @@ export const apiRequest = async ( return response.data; } catch (err) { - // const { - // response: { - // status: responseCode = null, - // statusText = '', - // data: { message = '', status: errorKey = '' } = {}, - // } = {}, - // code: statusCode = '', - // } = err as AxiosError; - // - // throw new Error( - // JSON.stringify({ - // statusCode, - // statusMessage: message || statusText, - // responseCode, - // errorKey, - // }), - // ); + const { + response: { + status: responseCode = null, + statusText = '', + data, + } = {}, + code: statusCode = '', + } = err as AxiosError; + + throw new Error( + JSON.stringify({ + statusCode, + statusMessage: statusText, + responseCode, + details: data + }), + ); } }; diff --git a/src/components/Experts/ExpertDetails.tsx b/src/components/Experts/ExpertDetails.tsx index 7fe4283..f598f57 100644 --- a/src/components/Experts/ExpertDetails.tsx +++ b/src/components/Experts/ExpertDetails.tsx @@ -15,9 +15,9 @@ import { getStorageValue } from '../../hooks/useLocalStorage'; import { AUTH_TOKEN_KEY, SESSION_DATA } from '../../constants/common'; import { ScheduleModal } from '../Modals/ScheduleModal'; import { ScheduleModalResult } from '../Modals/ScheduleModalResult'; -import SignalrConnection from "../../lib/signalr-connection"; -import {useRouter} from "../../navigation"; -import {useLocalStorage} from "../../hooks/useLocalStorage"; +import SignalrConnection from '../../lib/signalr-connection'; +import { useRouter } from '../../navigation'; +import { useLocalStorage } from '../../hooks/useLocalStorage'; type ExpertDetailsProps = { expert: ExpertDetails; @@ -38,30 +38,28 @@ export const ExpertCard: FC = ({ expert, locale, expertId }) const isRus = locale === Locale.ru; const { publicCoachDetails: { tags = [], sessionCost = 0, sessionDuration = 0, coachLanguages = [] , id, botUserId} } = expert || {}; const [jwt] = useLocalStorage(AUTH_TOKEN_KEY, ''); - const { joinChatPerson, addListener } = SignalrConnection(); + const { joinChatPerson, addListener, closeConnection } = SignalrConnection(); const router = useRouter(); const onConnected = (flag: boolean)=>{ if (flag){ - + console.log('here'); } } useEffect(() => { - addListener('onConnected', onConnected) + addListener('onConnected', onConnected); + document?.addEventListener('show_pay_form', handleShowPayForm); + + return () => { + closeConnection(); + document?.removeEventListener('show_pay_form', handleShowPayForm); + } }, []); - const handleJoinChat = () =>{ - joinChatPerson(id).then((res: any) =>{ - console.log('RES', res) - router.push(`/account/messages/${res.id}`); - }) - } - - const handleJoinAIChat = () =>{ - joinChatPerson(botUserId).then((res: any) =>{ - console.log('RES', res) - router.push(`/account/messages/${res.id}`); + const handleJoinChat = (id: number) => { + joinChatPerson(id).then((res: any) => { + router.push(`/account/messages/${res.id}` as string); }) } @@ -74,7 +72,7 @@ export const ExpertCard: FC = ({ expert, locale, expertId }) } else { setShowSchedulerModal(false); const showAuth = new Event('show_auth_enter'); - document.dispatchEvent(showAuth); + document?.dispatchEvent(showAuth); } } } @@ -84,13 +82,6 @@ export const ExpertCard: FC = ({ expert, locale, expertId }) setMode('pay'); } - useEffect(() => { - document.addEventListener('show_pay_form', handleShowPayForm); - return () => { - document.removeEventListener('show_pay_form', handleShowPayForm); - }; - }, []); - const onSchedulerHandle = () => { setMode('data'); setShowSchedulerModal(true); @@ -116,18 +107,24 @@ export const ExpertCard: FC = ({ expert, locale, expertId }) -
- - {/* - - - Video - - */} -
+ {jwt && ( +
+ + {botUserId && ( + + )} + {/* + + + Video + + */} +
+ )}
{/*

{}

*/} @@ -158,19 +155,6 @@ export const ExpertCard: FC = ({ expert, locale, expertId })
{`${sessionCost}€`} / {`${sessionDuration}${isRus ? 'мин' : 'min'}`}
- {jwt && ( -
- - {i18nText('chat.join', locale)} -   - {botUserId && ( - {i18nText('chat.joinAI', locale)} - )} -
- )}
localStorage.getItem(AUTH_TOKEN_KEY) } as IHttpConnectionOptions; this.connection = new HubConnectionBuilder() - .withUrl(URL, options) + .withUrl(`${BASE_URL}/hubs/chat`, options) .withAutomaticReconnect() .configureLogging(LogLevel.Debug) .build(); @@ -52,7 +50,7 @@ class SignalConnector { this.events[name] = func; } - public closeConnection = () =>{ + public closeConnection = () => { this.connection.stop(); } diff --git a/src/styles/_default.scss b/src/styles/_default.scss index c871c19..01dcb18 100644 --- a/src/styles/_default.scss +++ b/src/styles/_default.scss @@ -823,6 +823,7 @@ a { flex: 0 0 100%; display: flex; gap: 16px; + flex-direction: column; .btn-apply, .btn-video {