Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | /**
* EditMeetingDialog
* Allows organizers to edit location, start/end time, agenda and notes
* of an existing partner meeting.
*/
import React, { useEffect, useState } from 'react';
import {
Box,
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
TextField,
useMediaQuery,
useTheme,
} from '@mui/material';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useTranslation } from 'react-i18next';
import {
updateMeeting,
type PartnerMeetingDTO,
type UpdateMeetingRequest,
} from '@/services/api/partnerMeetingsApi';
interface EditMeetingDialogProps {
open: boolean;
meeting: PartnerMeetingDTO | null;
onClose: () => void;
}
const EditMeetingDialog: React.FC<EditMeetingDialogProps> = ({ open, meeting, onClose }) => {
const { t } = useTranslation('partners');
const queryClient = useQueryClient();
const theme = useTheme();
const isFullScreen = useMediaQuery(theme.breakpoints.down('md'));
const [form, setForm] = useState<UpdateMeetingRequest>({});
useEffect(() => {
if (meeting) {
setForm({
location: meeting.location ?? '',
startTime: meeting.startTime ?? '',
endTime: meeting.endTime ?? '',
agenda: meeting.agenda ?? '',
notes: meeting.notes ?? '',
});
}
}, [meeting]);
const editMutation = useMutation({
mutationFn: (req: UpdateMeetingRequest) => updateMeeting(meeting!.id, req),
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: ['partnerMeetings'] });
handleClose();
},
});
const handleSubmit = () => {
if (!meeting) return;
editMutation.mutate({
location: form.location?.trim() || undefined,
startTime: form.startTime || undefined,
endTime: form.endTime || undefined,
agenda: form.agenda?.trim() || undefined,
notes: form.notes?.trim() || undefined,
});
};
const handleClose = () => {
editMutation.reset();
onClose();
};
const setField = <K extends keyof UpdateMeetingRequest>(
key: K,
value: UpdateMeetingRequest[K]
) => {
setForm((prev) => ({ ...prev, [key]: value }));
};
return (
<Dialog
open={open}
onClose={handleClose}
maxWidth="sm"
fullWidth
fullScreen={isFullScreen}
data-testid="edit-meeting-dialog"
>
<DialogTitle>{t('meetings.edit')}</DialogTitle>
<DialogContent>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, pt: 1 }}>
<Box sx={{ display: 'flex', gap: 2 }}>
<TextField
label={t('meetings.fields.startTime')}
type="time"
value={form.startTime ?? ''}
onChange={(e) => setField('startTime', e.target.value)}
InputLabelProps={{ shrink: true }}
inputProps={{ step: 300, 'data-testid': 'edit-start-time' }}
sx={{ flex: 1 }}
/>
<TextField
label={t('meetings.fields.endTime')}
type="time"
value={form.endTime ?? ''}
onChange={(e) => setField('endTime', e.target.value)}
InputLabelProps={{ shrink: true }}
inputProps={{ step: 300, 'data-testid': 'edit-end-time' }}
sx={{ flex: 1 }}
/>
</Box>
<TextField
label={t('meetings.fields.location')}
value={form.location ?? ''}
onChange={(e) => setField('location', e.target.value)}
inputProps={{ 'data-testid': 'edit-location' }}
/>
<TextField
label={t('meetings.fields.agenda')}
value={form.agenda ?? ''}
onChange={(e) => setField('agenda', e.target.value)}
multiline
rows={4}
inputProps={{ 'data-testid': 'edit-agenda' }}
/>
<TextField
label={t('meetings.fields.notes')}
value={form.notes ?? ''}
onChange={(e) => setField('notes', e.target.value)}
multiline
rows={3}
inputProps={{ 'data-testid': 'edit-notes' }}
/>
</Box>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} data-testid="edit-meeting-cancel">
{t('common:actions.cancel')}
</Button>
<Button
variant="contained"
onClick={handleSubmit}
disabled={editMutation.isPending}
data-testid="edit-meeting-submit"
>
{editMutation.isPending ? t('common:actions.saving') : t('common:actions.save')}
</Button>
</DialogActions>
</Dialog>
);
};
export default EditMeetingDialog;
|