Skip to content

Commit

Permalink
fix(congregations): update updater function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao authored Jun 20, 2023
1 parent 2eca1c7 commit 2118293
Showing 1 changed file with 78 additions and 81 deletions.
159 changes: 78 additions & 81 deletions src/features/publicTalks/PublicTalkEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,94 +9,91 @@ import TextField from '@mui/material/TextField';
import Typography from '@mui/material/Typography';

const PublicTalkEditor = ({ isNew, handleSaveData, public_talk, language }) => {
const [isEdit, setIsEdit] = useState(isNew);
const [title, setTitle] = useState('');
const [isEdit, setIsEdit] = useState(isNew);
const [title, setTitle] = useState('');

const handleEdit = () => {
setIsEdit(true);
};
const handleEdit = () => {
setIsEdit(true);
};

const handleCancel = () => {
setIsEdit(false);
if (isNew) setTitle('');
if (!isNew) setTitle(public_talk[language.toUpperCase()]?.title || '');
};
const handleCancel = () => {
setIsEdit(false);
if (isNew) setTitle('');
if (!isNew) setTitle(public_talk[language.toUpperCase()]?.title || '');
};

const handleSave = () => {
handleSaveData(title);
setIsEdit(isNew ? true : false);
setTitle('');
};
const handleSave = () => {
handleSaveData(language, title);
setIsEdit(isNew ? true : false);
setTitle('');
};

useEffect(() => {
if (isNew) setTitle('');
if (!isNew) setTitle(public_talk[language.toUpperCase()]?.title || '');
}, [isNew, public_talk, language]);
useEffect(() => {
if (isNew) setTitle('');
if (!isNew) setTitle(public_talk[language.toUpperCase()]?.title || '');
}, [isNew, public_talk, language]);

useEffect(() => {
setIsEdit(isNew);
}, [isNew]);
useEffect(() => {
setIsEdit(isNew);
}, [isNew]);

return (
<Box>
<Box sx={{ display: 'flex', gap: '5px', alignItems: 'flex-start' }}>
{language !== 'E' && (
<Typography
sx={{
backgroundColor: '#3f51b5',
width: '60px',
textAlign: 'center',
fontSize: '20px',
fontWeight: 'bold',
color: 'white',
padding: '0 10px',
height: '40px',
lineHeight: '40px',
borderRadius: '5px',
}}
>
{language.toUpperCase()}
</Typography>
)}
<Box sx={{ width: '100%' }}>
<TextField
label="Source"
variant="outlined"
size="small"
fullWidth
InputProps={{ readOnly: !isEdit }}
value={title}
onChange={(e) => setTitle(e.target.value)}
/>
{!isNew && public_talk[language] && (
<Typography
align="right"
sx={{ fontSize: '14px', marginTop: '8px', fontStyle: 'italic', marginRight: '10px' }}
>
{new Date(public_talk[language].modified).toLocaleString()}
</Typography>
)}
</Box>
return (
<Box>
<Box sx={{ display: 'flex', gap: '5px', alignItems: 'flex-start' }}>
{language !== 'E' && (
<Typography
sx={{
backgroundColor: '#3f51b5',
width: '60px',
textAlign: 'center',
fontSize: '20px',
fontWeight: 'bold',
color: 'white',
padding: '0 10px',
height: '40px',
lineHeight: '40px',
borderRadius: '5px',
}}
>
{language.toUpperCase()}
</Typography>
)}
<Box sx={{ width: '100%' }}>
<TextField
label='Source'
variant='outlined'
size='small'
fullWidth
InputProps={{ readOnly: !isEdit }}
value={title}
onChange={(e) => setTitle(e.target.value)}
/>
{!isNew && public_talk[language] && (
<Typography align='right' sx={{ fontSize: '14px', marginTop: '8px', fontStyle: 'italic', marginRight: '10px' }}>
{new Date(public_talk[language].modified).toLocaleString()}
</Typography>
)}
</Box>

{!isEdit && (
<IconButton aria-label="edit" color="info" onClick={handleEdit}>
<EditIcon />
</IconButton>
)}
{isEdit && !isNew && (
<IconButton aria-label="save" color="error" onClick={handleCancel}>
<ClearIcon />
</IconButton>
)}
{isEdit && (
<IconButton aria-label="save" color="success" onClick={handleSave}>
{isNew && <AddCircleIcon />}
{!isNew && <CheckIcon />}
</IconButton>
)}
</Box>
</Box>
);
{!isEdit && (
<IconButton aria-label='edit' color='info' onClick={handleEdit}>
<EditIcon />
</IconButton>
)}
{isEdit && !isNew && (
<IconButton aria-label='save' color='error' onClick={handleCancel}>
<ClearIcon />
</IconButton>
)}
{isEdit && (
<IconButton aria-label='save' color='success' onClick={handleSave}>
{isNew && <AddCircleIcon />}
{!isNew && <CheckIcon />}
</IconButton>
)}
</Box>
</Box>
);
};

export default PublicTalkEditor;

0 comments on commit 2118293

Please sign in to comment.