blob: 6c0fc06814d766a8eab320e2499aaf7a86c478d8 [file] [log] [blame]
simon2d3b6532022-11-08 21:01:57 -05001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
18
simonf929a362022-11-18 16:53:45 -050019import { Box, CircularProgress, Grid, IconButtonProps, Stack, Typography } from '@mui/material';
20import { ComponentType, ReactNode } from 'react';
simon4e7445c2022-11-16 21:18:46 -050021import { useTranslation } from 'react-i18next';
simon2d3b6532022-11-08 21:01:57 -050022
23import {
24 CallingAnswerAudioButton,
25 CallingAnswerVideoButton,
simonf929a362022-11-18 16:53:45 -050026 CallingCancelButton,
simon2d3b6532022-11-08 21:01:57 -050027 CallingRefuseButton,
28} from '../components/CallButtons';
29
30export type CallPendingProps = {
31 pending: PendingStatus;
32 caller?: CallerStatus;
33 medium?: CommunicationMedium;
34};
35
36type PendingStatus = 'caller' | 'receiver';
37type CallerStatus = 'calling' | 'connecting';
38type CommunicationMedium = 'audio' | 'video';
39
simon2d3b6532022-11-08 21:01:57 -050040export const CallPending = (props: CallPendingProps) => {
41 return (
42 <Stack
43 direction="column"
44 justifyContent="center"
45 alignItems="center"
46 height="100%"
47 spacing={4}
48 sx={{
49 backgroundColor: 'black',
50 }}
51 >
52 <Box
53 sx={{
54 position: 'relative',
55 display: 'flex',
56 alignItems: 'center',
57 justifyContent: 'center',
58 width: '100%',
59 height: '30%',
60 }}
61 >
62 <Box
63 sx={{
64 aspectRatio: '1',
65 height: '100%',
66 position: 'absolute',
67 }}
68 >
69 <CircularProgress
70 disableShrink
71 thickness={1}
72 size="100%"
73 sx={{
74 position: 'absolute',
75 color: 'white',
76 zIndex: 1,
77 }}
78 />
79 <img
80 // TODO: Insert incoming caller icon here
simonf929a362022-11-18 16:53:45 -050081 alt="contact profile picture"
simon2d3b6532022-11-08 21:01:57 -050082 style={{
83 position: 'absolute',
84 objectFit: 'cover',
85 width: '100%',
86 height: '100%',
87 maxWidth: '100%',
88 borderRadius: '50%',
89 aspectRatio: '1',
90 }}
91 />
92 </Box>
93 </Box>
94 {props.pending === 'caller' ? (
95 <CallPendingCallerInterface {...props} />
96 ) : (
97 <CallPendingReceiverInterface {...props} />
98 )}
99 </Stack>
100 );
101};
102
simonf929a362022-11-18 16:53:45 -0500103const CallPendingDetails = ({
104 title,
105 buttons,
106}: {
107 title: ReactNode;
108 buttons: {
109 ButtonComponent: ComponentType<IconButtonProps>;
110 title: ReactNode;
111 }[];
112}) => {
simon2d3b6532022-11-08 21:01:57 -0500113 return (
simon4e7445c2022-11-16 21:18:46 -0500114 <>
simon2d3b6532022-11-08 21:01:57 -0500115 <Typography variant="h1" color="white">
simonf929a362022-11-18 16:53:45 -0500116 {title}
simon2d3b6532022-11-08 21:01:57 -0500117 </Typography>
simon4e7445c2022-11-16 21:18:46 -0500118 <Box width="50%">
simonf929a362022-11-18 16:53:45 -0500119 <Grid container justifyContent="center">
120 {buttons.map(({ ButtonComponent, title: buttonTitle }, i) => (
121 <Grid item key={i} xs={4}>
122 <Stack direction="column" alignItems="center" spacing={1} sx={{}}>
123 <ButtonComponent color="inherit" size="large" />
124 <Typography variant="body2" color="white" sx={{ opacity: 0.75 }}>
125 {buttonTitle}
126 </Typography>
127 </Stack>
128 </Grid>
129 ))}
130 </Grid>
simon4e7445c2022-11-16 21:18:46 -0500131 </Box>
132 </>
simon2d3b6532022-11-08 21:01:57 -0500133 );
134};
135
simonf929a362022-11-18 16:53:45 -0500136export const CallPendingCallerInterface = ({ caller }: CallPendingProps) => {
simon4e7445c2022-11-16 21:18:46 -0500137 const { t } = useTranslation();
simonf929a362022-11-18 16:53:45 -0500138
139 // TODO: Remove the dummy name
140 const defaultName = 'Alex Thérieur';
simon2d3b6532022-11-08 21:01:57 -0500141 return (
simonf929a362022-11-18 16:53:45 -0500142 <CallPendingDetails
143 title={
144 caller === 'calling'
145 ? t('calling', {
146 member0: defaultName,
147 })
148 : t('connecting')
149 }
150 buttons={[
151 {
152 ButtonComponent: CallingCancelButton,
153 title: t('end_call'),
154 },
155 ]}
156 />
157 );
158};
159
160export const CallPendingReceiverInterface = ({ medium, caller }: CallPendingProps) => {
161 const { t } = useTranslation();
162
163 // TODO: Remove the dummy name
164 const defaultName = 'Alain Thérieur';
165
166 return (
167 <CallPendingDetails
168 title={
169 caller === 'connecting'
170 ? t('connecting')
171 : t('incoming_call', {
172 context: medium,
173 member0: defaultName,
174 })
175 }
176 buttons={[
177 {
178 ButtonComponent: CallingRefuseButton,
179 title: t('refuse_call'),
180 },
181 {
182 ButtonComponent: CallingAnswerAudioButton,
183 title: t('accept_call_audio'),
184 },
185 {
186 ButtonComponent: CallingAnswerVideoButton,
187 title: t('accept_call_video'),
188 },
189 ]}
190 />
simon2d3b6532022-11-08 21:01:57 -0500191 );
192};