Skip to content

Commit

Permalink
feat: resources conversations styles (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
annarhughes authored Dec 17, 2024
1 parent 31079c4 commit c5fe77f
Show file tree
Hide file tree
Showing 16 changed files with 415 additions and 141 deletions.
2 changes: 0 additions & 2 deletions components/cards/AccountActionsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ const AccountActionsCard = () => {
id="delete-account-button"
variant="outlined"
sx={{
border: `solid 2px ${theme.palette.primary.dark}`,
color: theme.palette.primary.dark,
'&:hover': {
border: `solid 2px ${theme.palette.primary.dark}`,
background: theme.palette.primary.dark,
color: theme.palette.common.white,
},
Expand Down
16 changes: 9 additions & 7 deletions components/course/CourseHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import { EventUserData } from '../../utils/logEvent';
import Link from '../common/Link';
import Header from '../layout/Header';

const buttonStyle = {
background: theme.palette.background.default,
boxShadow: 'none !important',
':hover': {
background: 'white',
},
} as const;

export interface CourseHeaderProps {
name: string;
description: ISbRichtext;
Expand All @@ -29,13 +37,7 @@ const CourseHeader = (props: CourseHeaderProps) => {

return (
<Header {...headerProps}>
<Button
variant="outlined"
sx={{ background: theme.palette.background.default }}
href="/courses"
size="small"
component={Link}
>
<Button variant="outlined" sx={buttonStyle} href="/courses" size="small" component={Link}>
{t('backToCourses')}
</Button>
</Header>
Expand Down
2 changes: 1 addition & 1 deletion components/layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const Footer = () => {
alt={tS(partner.logoAlt)}
src={partner.logo}
fill
sizes="100vw"
sizes="300px"
style={{
objectFit: 'contain',
objectPosition: 'left',
Expand Down
2 changes: 1 addition & 1 deletion components/layout/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const TopBar = () => {
alt={tS('alt.bloomLogo')}
src={bloomLogo}
fill
sizes="100vw"
sizes="250px"
style={{
objectFit: 'contain',
}}
Expand Down
5 changes: 3 additions & 2 deletions components/resources/ResourceCompleteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ const errorStyle = {
} as const;

interface ResourceCompleteButtonProps {
resourceName: string;
category: RESOURCE_CATEGORIES;
storyId: number;
eventData: EventUserData;
}

export const ResourceCompleteButton = (props: ResourceCompleteButtonProps) => {
const { category, storyId, eventData } = props;
const { resourceName, category, storyId, eventData } = props;

const t = useTranslations('Resources');

Expand Down Expand Up @@ -79,7 +80,7 @@ export const ResourceCompleteButton = (props: ResourceCompleteButtonProps) => {
<Button
color="primary"
size="medium"
variant="contained"
variant="outlined"
onClick={completeResourceAction}
startIcon={<CheckCircleIcon color="error" />}
>
Expand Down
144 changes: 144 additions & 0 deletions components/resources/ResourceConversationAudio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { Link, Typography } from '@mui/material';
import { ISbRichtext } from '@storyblok/react';
import { useTranslations } from 'next-intl';
import { useCallback, useEffect, useState } from 'react';
import { PROGRESS_STATUS } from '../../constants/enums';
import {
RESOURCE_CONVERSATION_COMPLETE_ERROR,
RESOURCE_CONVERSATION_COMPLETE_REQUEST,
RESOURCE_CONVERSATION_COMPLETE_SUCCESS,
RESOURCE_CONVERSATION_STARTED_ERROR,
RESOURCE_CONVERSATION_STARTED_REQUEST,
RESOURCE_CONVERSATION_STARTED_SUCCESS,
RESOURCE_CONVERSATION_TRANSCRIPT_CLOSED,
RESOURCE_CONVERSATION_TRANSCRIPT_OPENED,
} from '../../constants/events';
import { useTypedSelector } from '../../hooks/store';
import { useCompleteResourceMutation, useStartResourceMutation } from '../../store/api';
import logEvent, { EventUserData } from '../../utils/logEvent';
import Audio from '../video/Audio';
import VideoTranscriptModal from '../video/VideoTranscriptModal';

export interface EventData extends EventUserData {
resource_name: string;
resource_storyblok_id: number;
resource_progress: PROGRESS_STATUS;
}

interface ResourceConversationAudioProps {
eventData: EventData;
resourceProgress: PROGRESS_STATUS;
name: string;
storyId: number;
audio: string;
audio_transcript: ISbRichtext;
}

export const ResourceConversationAudio = (props: ResourceConversationAudioProps) => {
const { eventData, storyId, resourceProgress, name, audio_transcript, audio } = props;
const [openTranscriptModal, setOpenTranscriptModal] = useState<boolean | null>(null);
const [startResourceConversation] = useStartResourceMutation();
const [completeResourceConversation] = useCompleteResourceMutation();
const isLoggedIn = useTypedSelector((state) => Boolean(state.user.id));

const t = useTranslations('Resources');

const callStartResourceConversation = useCallback(async () => {
logEvent(RESOURCE_CONVERSATION_STARTED_REQUEST, eventData);

const startResourceConversationResponse = await startResourceConversation({
storyblokId: storyId,
});

if (startResourceConversationResponse.data) {
logEvent(RESOURCE_CONVERSATION_STARTED_SUCCESS, eventData);
}

if (startResourceConversationResponse.error) {
const error = startResourceConversationResponse.error;

logEvent(RESOURCE_CONVERSATION_STARTED_ERROR, eventData);
(window as any).Rollbar?.error('ResourceConversation started error', error);

throw error;
}
}, [startResourceConversation, eventData, name, storyId]);

const callCompleteResourceConversation = useCallback(async () => {
logEvent(RESOURCE_CONVERSATION_COMPLETE_REQUEST, eventData);

const completeResourceConversationResponse = await completeResourceConversation({
storyblokId: storyId,
});

if (completeResourceConversationResponse.data) {
logEvent(RESOURCE_CONVERSATION_COMPLETE_SUCCESS, eventData);
}

if (completeResourceConversationResponse.error) {
const error = completeResourceConversationResponse.error;

logEvent(RESOURCE_CONVERSATION_COMPLETE_ERROR, eventData);
(window as any).Rollbar?.error('ResourceConversation completed error', error);

throw error;
}
}, [completeResourceConversation, eventData, name, storyId]);

useEffect(() => {
if (openTranscriptModal === null) return;

logEvent(
openTranscriptModal
? RESOURCE_CONVERSATION_TRANSCRIPT_OPENED
: RESOURCE_CONVERSATION_TRANSCRIPT_CLOSED,
eventData,
);
if (isLoggedIn && openTranscriptModal && resourceProgress === PROGRESS_STATUS.NOT_STARTED) {
callStartResourceConversation();
}
}, [
callStartResourceConversation,
openTranscriptModal,
eventData,
name,
resourceProgress,
isLoggedIn,
]);

const audioStarted = () => {
if (isLoggedIn && resourceProgress === PROGRESS_STATUS.NOT_STARTED) {
callStartResourceConversation();
}
};

const audioFinished = () => {
if (isLoggedIn && resourceProgress !== PROGRESS_STATUS.COMPLETED) {
callCompleteResourceConversation();
}
};

return (
<>
<Audio
url={audio}
setAudioStarted={audioStarted}
setAudioFinished={audioFinished}
eventData={eventData}
eventPrefix="RESOURCE_CONVERSATION"
/>
<Typography sx={{ my: '1rem !important' }}>
{t.rich('conversationTranscriptLink', {
link: (children) => <Link onClick={() => setOpenTranscriptModal(true)}>{children}</Link>,
})}
</Typography>

<VideoTranscriptModal
videoName={name}
content={audio_transcript}
setOpenTranscriptModal={setOpenTranscriptModal}
openTranscriptModal={openTranscriptModal}
/>
</>
);
};
62 changes: 22 additions & 40 deletions components/resources/ResourceShortVideo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Link, Typography } from '@mui/material';
import { ISbRichtext } from '@storyblok/react';
import { useTranslations } from 'next-intl';
import { useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { PROGRESS_STATUS } from '../../constants/enums';
import {
RESOURCE_SHORT_VIDEO_COMPLETE_ERROR,
Expand All @@ -12,8 +12,8 @@ import {
RESOURCE_SHORT_VIDEO_STARTED_SUCCESS,
RESOURCE_SHORT_VIDEO_TRANSCRIPT_CLOSED,
RESOURCE_SHORT_VIDEO_TRANSCRIPT_OPENED,
RESOURCE_SHORT_VIDEO_VIEWED,
} from '../../constants/events';
import { useTypedSelector } from '../../hooks/store';
import { useCompleteResourceMutation, useStartResourceMutation } from '../../store/api';
import logEvent, { EventUserData } from '../../utils/logEvent';
import Video from '../video/Video';
Expand All @@ -36,18 +36,15 @@ interface ResourceShortVideoProps {

export const ResourceShortVideo = (props: ResourceShortVideoProps) => {
const { eventData, storyId, resourceProgress, name, video_transcript, video } = props;
const [videoStarted, setVideoStarted] = useState<boolean>(false);
const [videoFinished, setVideoFinished] = useState<boolean>(false);
const [openTranscriptModal, setOpenTranscriptModal] = useState<boolean | null>(null);
const [startResourceShort] = useStartResourceMutation();
const [completeResourceShort] = useCompleteResourceMutation();
const isLoggedIn = useTypedSelector((state) => Boolean(state.user.id));

const t = useTranslations('Resources');

async function callStartResourceShort() {
logEvent(RESOURCE_SHORT_VIDEO_STARTED_REQUEST, {
...eventData,
resource_name: name,
});
const callStartResourceShort = useCallback(async () => {
logEvent(RESOURCE_SHORT_VIDEO_STARTED_REQUEST, eventData);

const startResourceShortResponse = await startResourceShort({
storyblokId: storyId,
Expand All @@ -65,13 +62,10 @@ export const ResourceShortVideo = (props: ResourceShortVideoProps) => {

throw error;
}
}
}, [startResourceShort, eventData, storyId]);

async function callCompleteResourceShort() {
logEvent(RESOURCE_SHORT_VIDEO_COMPLETE_REQUEST, {
...eventData,
resource_name: name,
});
const callCompleteResourceShort = useCallback(async () => {
logEvent(RESOURCE_SHORT_VIDEO_COMPLETE_REQUEST, eventData);

const completeResourceShortResponse = await completeResourceShort({
storyblokId: storyId,
Expand All @@ -89,7 +83,7 @@ export const ResourceShortVideo = (props: ResourceShortVideoProps) => {

throw error;
}
}
}, [completeResourceShort, eventData, storyId]);

useEffect(() => {
if (openTranscriptModal === null) return;
Expand All @@ -98,50 +92,38 @@ export const ResourceShortVideo = (props: ResourceShortVideoProps) => {
openTranscriptModal
? RESOURCE_SHORT_VIDEO_TRANSCRIPT_OPENED
: RESOURCE_SHORT_VIDEO_TRANSCRIPT_CLOSED,
{
...eventData,
resource_name: name,
course_name: name,
},
eventData,
);
if (openTranscriptModal && resourceProgress === PROGRESS_STATUS.NOT_STARTED) {
if (isLoggedIn && openTranscriptModal && resourceProgress === PROGRESS_STATUS.NOT_STARTED) {
callStartResourceShort();
}
}, [openTranscriptModal, eventData, name, resourceProgress]);

useEffect(() => {
if (!videoStarted || resourceProgress !== PROGRESS_STATUS.NOT_STARTED) return;
}, [callStartResourceShort, openTranscriptModal, eventData, name, resourceProgress, isLoggedIn]);

if (videoStarted) {
const videoStarted = () => {
if (isLoggedIn && resourceProgress === PROGRESS_STATUS.NOT_STARTED) {
callStartResourceShort();
}
}, [videoStarted, resourceProgress]);
};

useEffect(() => {
if (!videoFinished || resourceProgress === PROGRESS_STATUS.COMPLETED) return;

if (videoFinished) {
const videoFinished = () => {
if (isLoggedIn && resourceProgress !== PROGRESS_STATUS.COMPLETED) {
callCompleteResourceShort();
}
}, [videoFinished, resourceProgress]);

useEffect(() => {
logEvent(RESOURCE_SHORT_VIDEO_VIEWED, eventData);
}, []);
};

return (
video && (
<>
<Video
url={video.url}
setVideoStarted={setVideoStarted}
setVideoFinished={setVideoFinished}
setVideoStarted={videoStarted}
setVideoFinished={videoFinished}
eventData={eventData}
eventPrefix="RESOURCE_SHORT"
autoplay={true}
/>
<Typography sx={{ my: '1rem !important' }}>
{t.rich('transcriptLink', {
{t.rich('videoTranscriptLink', {
link: (children) => (
<Link onClick={() => setOpenTranscriptModal(true)}>{children}</Link>
),
Expand Down
20 changes: 11 additions & 9 deletions components/session/SessionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import theme from '../../styles/theme';
import Link from '../common/Link';
import Header from '../layout/Header';

const buttonStyle = {
background: theme.palette.background.default,
boxShadow: 'none !important',
':hover': {
background: 'white',
},
} as const;

const sessionSubtitleStyle = {
marginTop: '0.75rem !important',
} as const;
Expand Down Expand Up @@ -58,21 +66,15 @@ export const SessionHeader = (props: SessionHeaderProps) => {
imageAlt={headerProps.imageAlt}
progressStatus={sessionProgress}
>
<Button
variant="outlined"
href="/courses"
sx={{ background: theme.palette.background.default }}
size="small"
component={Link}
>
<Button variant="contained" href="/courses" sx={buttonStyle} size="small" component={Link}>
Courses
</Button>

<CircleIcon color="error" sx={{ ...dotStyle, marginX: 1 }} />

<Button
variant="outlined"
sx={{ background: theme.palette.background.default }}
variant="contained"
sx={buttonStyle}
href={`/${course.full_slug}`}
size="small"
component={Link}
Expand Down
Loading

0 comments on commit c5fe77f

Please sign in to comment.