Merge branch 'fix-if-guardian-is-not-available' into 'dev'

Fix issue #78 - Show alert if no one is available Guardian/Helper

See merge request nitro/nitro-react!92
This commit is contained in:
skeletor 2022-11-08 00:03:33 +00:00
commit f13eb1fed4
4 changed files with 67 additions and 8 deletions

View File

@ -7,6 +7,8 @@ export class GuideSessionState
public static readonly USER_PENDING: string = 'USER_PENDING'; public static readonly USER_PENDING: string = 'USER_PENDING';
public static readonly USER_ONGOING: string = 'USER_ONGOING'; public static readonly USER_ONGOING: string = 'USER_ONGOING';
public static readonly USER_FEEDBACK: string = 'USER_FEEDBACK'; public static readonly USER_FEEDBACK: string = 'USER_FEEDBACK';
public static readonly USER_NO_HELPERS: string = 'USER_NO_HELPERS';
public static readonly USER_SOMETHING_WRONG: string = 'USER_SOMETHING_WRONG';
public static readonly USER_THANKS: string = 'USER_THANKS'; public static readonly USER_THANKS: string = 'USER_THANKS';
public static readonly USER_GUIDE_DISCONNECTED: string = 'USER_GUIDE_DISCONNECTED'; public static readonly USER_GUIDE_DISCONNECTED: string = 'USER_GUIDE_DISCONNECTED';
public static readonly GUIDE_TOOL_MENU: string = 'GUIDE_TOOL_MENU'; public static readonly GUIDE_TOOL_MENU: string = 'GUIDE_TOOL_MENU';

View File

@ -1,4 +1,4 @@
import { GuideOnDutyStatusMessageEvent, GuideSessionAttachedMessageEvent, GuideSessionDetachedMessageEvent, GuideSessionEndedMessageEvent, GuideSessionInvitedToGuideRoomMessageEvent, GuideSessionMessageMessageEvent, GuideSessionOnDutyUpdateMessageComposer, GuideSessionPartnerIsTypingMessageEvent, GuideSessionStartedMessageEvent, ILinkEventTracker, PerkAllowancesMessageEvent, PerkEnum } from '@nitrots/nitro-renderer'; import { GuideOnDutyStatusMessageEvent, GuideSessionAttachedMessageEvent, GuideSessionDetachedMessageEvent, GuideSessionEndedMessageEvent, GuideSessionErrorMessageEvent, GuideSessionInvitedToGuideRoomMessageEvent, GuideSessionMessageMessageEvent, GuideSessionOnDutyUpdateMessageComposer, GuideSessionPartnerIsTypingMessageEvent, GuideSessionStartedMessageEvent, ILinkEventTracker, PerkAllowancesMessageEvent, PerkEnum } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useState } from 'react'; import { FC, useCallback, useEffect, useState } from 'react';
import { AddEventLinkTracker, GetConfiguration, GetSessionDataManager, GuideSessionState, GuideToolMessage, GuideToolMessageGroup, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api'; import { AddEventLinkTracker, GetConfiguration, GetSessionDataManager, GuideSessionState, GuideToolMessage, GuideToolMessageGroup, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api';
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common';
@ -9,7 +9,9 @@ import { GuideToolMenuView } from './views/GuideToolMenuView';
import { GuideToolOngoingView } from './views/GuideToolOngoingView'; import { GuideToolOngoingView } from './views/GuideToolOngoingView';
import { GuideToolUserCreateRequestView } from './views/GuideToolUserCreateRequestView'; import { GuideToolUserCreateRequestView } from './views/GuideToolUserCreateRequestView';
import { GuideToolUserFeedbackView } from './views/GuideToolUserFeedbackView'; import { GuideToolUserFeedbackView } from './views/GuideToolUserFeedbackView';
import { GuideToolUserNoHelpersView } from './views/GuideToolUserNoHelpersView';
import { GuideToolUserPendingView } from './views/GuideToolUserPendingView'; import { GuideToolUserPendingView } from './views/GuideToolUserPendingView';
import { GuideToolUserSomethingWrogView } from './views/GuideToolUserSomethingWrogView';
import { GuideToolUserThanksView } from './views/GuideToolUserThanksView'; import { GuideToolUserThanksView } from './views/GuideToolUserThanksView';
export const GuideToolView: FC<{}> = props => export const GuideToolView: FC<{}> = props =>
@ -77,6 +79,14 @@ export const GuideToolView: FC<{}> = props =>
setHeaderText(LocalizeText('guide.help.request.user.thanks.title')); setHeaderText(LocalizeText('guide.help.request.user.thanks.title'));
setNoCloseButton(false); setNoCloseButton(false);
break; break;
case GuideSessionState.USER_NO_HELPERS:
setHeaderText(LocalizeText('guide.help.request.no_tour_guides.heading'));
setNoCloseButton(false);
break;
case GuideSessionState.USER_SOMETHING_WRONG:
setHeaderText(LocalizeText('guide.help.request.user.guide.disconnected.error.heading'));
setNoCloseButton(false);
break;
} }
setSessionState(newState); setSessionState(newState);
@ -92,7 +102,7 @@ export const GuideToolView: FC<{}> = props =>
return; return;
case GuideToolEvent.HIDE_GUIDE_TOOL: case GuideToolEvent.HIDE_GUIDE_TOOL:
setIsVisible(false); setIsVisible(false);
return; return;
case GuideToolEvent.TOGGLE_GUIDE_TOOL: case GuideToolEvent.TOGGLE_GUIDE_TOOL:
setIsVisible(value => !value); setIsVisible(value => !value);
return; return;
@ -136,7 +146,7 @@ export const GuideToolView: FC<{}> = props =>
setHelpRequestAverageTime(parser.roleSpecificWaitTime); setHelpRequestAverageTime(parser.roleSpecificWaitTime);
if(parser.asGuide && isOnDuty) updateSessionState(GuideSessionState.GUIDE_ACCEPT); if(parser.asGuide && isOnDuty) updateSessionState(GuideSessionState.GUIDE_ACCEPT);
if(!parser.asGuide) updateSessionState(GuideSessionState.USER_PENDING); if(!parser.asGuide) updateSessionState(GuideSessionState.USER_PENDING);
}); });
@ -222,6 +232,24 @@ export const GuideToolView: FC<{}> = props =>
} }
}); });
useMessageEvent<GuideSessionErrorMessageEvent>(GuideSessionErrorMessageEvent, event =>
{
const parser = event.getParser();
// SOMETHING_WRONG_REQUEST = 0, NO_HELPERS_AVAILABLE = 1, NO_GUARDIANS_AVAILABLE = 2
switch (parser['errorCode'])
{
case 0:
updateSessionState(GuideSessionState.USER_SOMETHING_WRONG);
break;
case 1:
case 2:
updateSessionState(GuideSessionState.USER_NO_HELPERS);
break;
}
});
useMessageEvent<GuideSessionDetachedMessageEvent>(GuideSessionDetachedMessageEvent, event => useMessageEvent<GuideSessionDetachedMessageEvent>(GuideSessionDetachedMessageEvent, event =>
{ {
setOngoingUserId(0); setOngoingUserId(0);
@ -232,7 +260,7 @@ export const GuideToolView: FC<{}> = props =>
if(isOnDuty) if(isOnDuty)
{ {
updateSessionState(GuideSessionState.GUIDE_TOOL_MENU); updateSessionState(GuideSessionState.GUIDE_TOOL_MENU);
} }
else else
@ -247,9 +275,9 @@ export const GuideToolView: FC<{}> = props =>
linkReceived: (url: string) => linkReceived: (url: string) =>
{ {
const parts = url.split('/'); const parts = url.split('/');
if(parts.length < 2) return; if(parts.length < 2) return;
switch(parts[1]) switch(parts[1])
{ {
case 'tour': case 'tour':
@ -286,7 +314,7 @@ export const GuideToolView: FC<{}> = props =>
SendMessageComposer(new GuideSessionOnDutyUpdateMessageComposer(!v, v ? false : isHandlingGuideRequests, v ? false : isHandlingHelpRequests, v ? false : isHandlingBullyReports)); SendMessageComposer(new GuideSessionOnDutyUpdateMessageComposer(!v, v ? false : isHandlingGuideRequests, v ? false : isHandlingHelpRequests, v ? false : isHandlingBullyReports));
return !v; return !v;
}); });
return; return;
case 'forum_link': case 'forum_link':
const url: string = GetConfiguration<string>('group.homepage.url', '').replace('%groupid%', GetConfiguration<string>('guide.help.alpha.groupid', '0')); const url: string = GetConfiguration<string>('group.homepage.url', '').replace('%groupid%', GetConfiguration<string>('guide.help.alpha.groupid', '0'));
@ -302,7 +330,7 @@ export const GuideToolView: FC<{}> = props =>
<NitroCardHeaderView headerText={ headerText } onCloseClick={ event => processAction('close') } noCloseButton={ noCloseButton } /> <NitroCardHeaderView headerText={ headerText } onCloseClick={ event => processAction('close') } noCloseButton={ noCloseButton } />
<NitroCardContentView className="text-black"> <NitroCardContentView className="text-black">
{ (sessionState === GuideSessionState.GUIDE_TOOL_MENU) && { (sessionState === GuideSessionState.GUIDE_TOOL_MENU) &&
<GuideToolMenuView isOnDuty={ isOnDuty } isHandlingGuideRequests={ isHandlingGuideRequests } setIsHandlingGuideRequests={ setIsHandlingGuideRequests } isHandlingHelpRequests={ isHandlingHelpRequests } setIsHandlingHelpRequests={ setIsHandlingHelpRequests } isHandlingBullyReports={ isHandlingBullyReports } setIsHandlingBullyReports={ setIsHandlingBullyReports } guidesOnDuty={ guidesOnDuty } helpersOnDuty={ helpersOnDuty } guardiansOnDuty={ guardiansOnDuty } processAction={ processAction } /> } <GuideToolMenuView isOnDuty={ isOnDuty } isHandlingGuideRequests={ isHandlingGuideRequests } setIsHandlingGuideRequests={ setIsHandlingGuideRequests } isHandlingHelpRequests={ isHandlingHelpRequests } setIsHandlingHelpRequests={ setIsHandlingHelpRequests } isHandlingBullyReports={ isHandlingBullyReports } setIsHandlingBullyReports={ setIsHandlingBullyReports } guidesOnDuty={ guidesOnDuty } helpersOnDuty={ helpersOnDuty } guardiansOnDuty={ guardiansOnDuty } processAction={ processAction } /> }
{ (sessionState === GuideSessionState.GUIDE_ACCEPT) && { (sessionState === GuideSessionState.GUIDE_ACCEPT) &&
<GuideToolAcceptView helpRequestDescription={ helpRequestDescription } helpRequestAverageTime={ helpRequestAverageTime } /> } <GuideToolAcceptView helpRequestDescription={ helpRequestDescription } helpRequestAverageTime={ helpRequestAverageTime } /> }
{ [ GuideSessionState.GUIDE_ONGOING, GuideSessionState.USER_ONGOING ].includes(sessionState) && { [ GuideSessionState.GUIDE_ONGOING, GuideSessionState.USER_ONGOING ].includes(sessionState) &&
@ -315,6 +343,10 @@ export const GuideToolView: FC<{}> = props =>
<GuideToolUserFeedbackView userName={ ongoingUsername } /> } <GuideToolUserFeedbackView userName={ ongoingUsername } /> }
{ (sessionState === GuideSessionState.USER_THANKS) && { (sessionState === GuideSessionState.USER_THANKS) &&
<GuideToolUserThanksView /> } <GuideToolUserThanksView /> }
{ (sessionState === GuideSessionState.USER_NO_HELPERS) &&
<GuideToolUserNoHelpersView /> }
{ (sessionState === GuideSessionState.USER_SOMETHING_WRONG) &&
<GuideToolUserSomethingWrogView /> }
</NitroCardContentView> </NitroCardContentView>
</NitroCardView> </NitroCardView>
); );

View File

@ -0,0 +1,13 @@
import { FC } from 'react';
import { LocalizeText } from '../../../api';
import { Column, Text } from '../../../common';
export const GuideToolUserNoHelpersView: FC<{}> = props =>
{
return (
<Column gap={ 1 }>
<Text bold>{ LocalizeText('guide.help.request.no_tour_guides.title') }</Text>
<Text>{ LocalizeText('guide.help.request.no_tour_guides.message') }</Text>
</Column>
);
};

View File

@ -0,0 +1,12 @@
import { FC } from 'react';
import { LocalizeText } from '../../../api';
import { Column, Text } from '../../../common';
export const GuideToolUserSomethingWrogView: FC<{}> = props =>
{
return (
<Column gap={ 1 }>
<Text>{ LocalizeText('guide.help.request.user.guide.disconnected.error.desc') }</Text>
</Column>
);
};