Skip to content

Added Claim Reward Button and improved styling of Profile.tsx #1795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 114 additions & 47 deletions frontend/src/components/Dialogs/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

import {
Dialog,
DialogContent,
Expand All @@ -11,9 +10,11 @@ import {
ListItem,
Typography,
LinearProgress,
Button,
Alert,
} from '@mui/material';

import BoltIcon from '@mui/icons-material/Bolt';
import RedeemIcon from '@mui/icons-material/Redeem';
import RobotAvatar from '../RobotAvatar';
import RobotInfo from '../RobotInfo';
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
Expand All @@ -29,6 +30,7 @@ const ProfileDialog = ({ open = false, onClose }: Props): JSX.Element => {
const { federation } = useContext<UseFederationStoreType>(FederationContext);
const { garage, slotUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
const { t } = useTranslation();
const [showClaimInfo, setShowClaimInfo] = useState<boolean>(false);

const slot = garage.getSlot();

Expand All @@ -42,77 +44,142 @@ const ProfileDialog = ({ open = false, onClose }: Props): JSX.Element => {
setLoadingRobots(Object.values(slot?.robots ?? {}).filter((robot) => robot.loading).length);
}, [slotUpdatedAt]);

const handleClaimReward = () => {
setShowClaimInfo(true);
};

return (
<Dialog
open={open}
onClose={onClose}
aria-labelledby='profile-title'
aria-describedby='profile-description'
aria-labelledby="profile-title"
aria-describedby="profile-description"
sx={{ '& .MuiDialog-paper': { minWidth: '300px', maxWidth: '500px', borderRadius: '8px' } }}
>
<div style={loading ? {} : { display: 'none' }}>
<LinearProgress />
<div style={{ display: loading ? 'block' : 'none', padding: '0' }}>
<LinearProgress sx={{ height: '6px', borderRadius: '4px' }} />
</div>
<DialogContent>
<Typography component='h5' variant='h5'>
{t('Your Robot')}
</Typography>
<List>
<Divider />

<ListItem className='profileNickname'>
<DialogContent sx={{ padding: '20px' }}>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: '16px',
}}
>
<Typography variant="h5" sx={{ fontWeight: 600, color: '#333' }}>
{t('Your Robot')}
</Typography>
<Button
variant="contained"
color="primary"
startIcon={<RedeemIcon />}
onClick={handleClaimReward}
sx={{
borderRadius: '20px',
textTransform: 'none',
padding: '6px 16px',
fontWeight: 500,
backgroundColor: '#1976d2', // Default primary color
'&:hover': { backgroundColor: '#1565c0' },
}}
>
{t('Claim Reward')}
</Button>
</div>

{showClaimInfo && (
<Alert
severity="info"
sx={{
marginBottom: '16px',
borderRadius: '8px',
backgroundColor: '#e3f2fd',
color: '#0d47a1',
}}
>
{t(
'To claim your rewards, please contact the coordinator of your last order. If the payment fails, you must contact the coordinator - do not generate a new invoice.',
)}
</Alert>
)}

<List sx={{ padding: 0 }}>
<Divider sx={{ margin: '12px 0', backgroundColor: '#e0e0e0' }} />

<ListItem
sx={{
padding: '12px 0',
alignItems: 'center',
'&:hover': { backgroundColor: '#f5f5f5', borderRadius: '4px' },
}}
>
<ListItemText>
<Typography component='h6' variant='h6'>
{!garage.getSlot()?.nickname && (
<div style={{ position: 'relative', left: '-7px' }}>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'left',
flexWrap: 'wrap',
width: 300,
}}
>
<BoltIcon sx={{ color: '#fcba03', height: '28px', width: '24px' }} />

<a>{garage.getSlot()?.nickname}</a>

<BoltIcon sx={{ color: '#fcba03', height: '28px', width: '24px' }} />
</div>
<Typography variant="h6" sx={{ fontWeight: 500, color: '#555' }}>
{garage.getSlot()?.nickname ? (
<div
style={{
display: 'flex',
alignItems: 'center',
gap: '8px',
flexWrap: 'wrap',
}}
>
<BoltIcon sx={{ color: '#fcba03', height: '24px', width: '24px' }} />
<span style={{ color: '#333', fontSize: '1.25rem' }}>
{garage.getSlot()?.nickname}
</span>
<BoltIcon sx={{ color: '#fcba03', height: '24px', width: '24px' }} />
</div>
) : (
<span style={{ color: '#888', fontStyle: 'italic' }}>{t('No nickname set')}</span>
)}
</Typography>

{loadingRobots > 0 ? (
<>
<b>{t('Looking for your robot!')}</b>
<LinearProgress />
</>
) : (
<></>
{loadingRobots > 0 && (
<div style={{ marginTop: '8px' }}>
<Typography variant="body2" sx={{ fontWeight: 600, color: '#888' }}>
{t('Looking for your robot!')}
</Typography>
<LinearProgress
sx={{ marginTop: '4px', height: '4px', borderRadius: '2px', backgroundColor: '#e0e0e0' }}
/>
</div>
)}
</ListItemText>

<ListItemAvatar>
<RobotAvatar
avatarClass='profileAvatar'
style={{ width: 65, height: 65 }}
avatarClass="profileAvatar"
style={{
width: 65,
height: 65,
border: '2px solid #fcba03',
borderRadius: '50%',
}}
hashId={garage.getSlot()?.hashId ?? ''}
/>
</ListItemAvatar>
</ListItem>

<Divider />
<Divider sx={{ margin: '12px 0', backgroundColor: '#e0e0e0' }} />
</List>

<Typography>
<b>{t('Coordinators that know your robot:')}</b>
<Typography
variant="subtitle1"
sx={{ fontWeight: 600, color: '#333', marginBottom: '12px' }}
>
{t('Coordinators that know your robot:')}
</Typography>

{federation.getCoordinators().map((coordinator: Coordinator): JSX.Element => {
{federation.getCoordinators().map((coordinator: Coordinator) => {
const coordinatorRobot = garage.getSlot()?.getRobot(coordinator.shortAlias);
return (
<div key={coordinator.shortAlias}>
<div
key={coordinator.shortAlias}
style={{ marginBottom: '12px', padding: '8px', borderRadius: '4px' }}
>
<RobotInfo
coordinator={coordinator}
onClose={onClose}
Expand All @@ -126,4 +193,4 @@ const ProfileDialog = ({ open = false, onClose }: Props): JSX.Element => {
);
};

export default ProfileDialog;
export default ProfileDialog;