Skip to content

Commit

Permalink
Add remaining fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasdeluna committed Nov 6, 2024
1 parent 3b5cc30 commit ab2a3b4
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 19 deletions.
10 changes: 9 additions & 1 deletion app/actions/MeetingTemplateActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { meetingTemplatesSchema } from '../reducers';
import { MeetingTemplates } from './ActionTypes';
import callAPI from './callAPI';
import type { EntityId } from '@reduxjs/toolkit';
import type { MeetingTemplate } from 'app/models';
import type { Dateish, MeetingTemplate } from 'app/models';

export const fetchAllMeetingTemplates = () =>
callAPI<MeetingTemplate[]>({
Expand All @@ -17,6 +17,14 @@ export const fetchAllMeetingTemplates = () =>
export function createMeetingTemplate(data: {
name: EntityId;
report: string;
location: string;
startTime: Dateish;
endTime: Dateish;
description: string;
mazemapPoi: number | null;
reportAuthor: EntityId;
invitedUsers: EntityId[];
invitedGroups: EntityId[];
}) {
return callAPI<MeetingTemplate>({
types: MeetingTemplates.CREATE,
Expand Down
9 changes: 9 additions & 0 deletions app/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { EventType } from './store/models/Event';
import type { PublicGroup } from './store/models/Group';
import type { Presence } from './store/models/Registration';
import type { EntityId } from '@reduxjs/toolkit';
import type Comment from 'app/store/models/Comment';
Expand Down Expand Up @@ -322,6 +323,14 @@ export type MeetingTemplate = {
id: EntityId;
name: string;
report: string;
location: string;
startTime: Dateish;
endTime: Dateish;
description: string;
mazemapPoi: number | null;
reportAuthor: PublicUser;
invitedUsers: PublicUser[];
invitedGroups: PublicGroup[];
createdBy: EntityId;
};

Expand Down
113 changes: 95 additions & 18 deletions app/routes/meetings/components/MeetingEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const MeetingEditor = () => {
},
[],
);
const [selectedTemplate, setSelectedTemplate] = useState<EntityId>(null);

const allMeetingTemplates = useAppSelector(selectAllMeetingTemplates);
const navigate = useNavigate();
Expand Down Expand Up @@ -284,28 +285,74 @@ const MeetingEditor = () => {
component={EditorField.Field}
key={meetingRefreshKey}
/>
<Field
name="template"
label="Velg en møtemal"
placeholder="Velg møtemal"
component={SelectInput.Field}
options={allMeetingTemplates.map((template) => ({
label: template.name,
value: template.id,
}))}
isSearchable={false}
onChange={(templateId) => {
const selectedTemplate = allMeetingTemplates.find(
(template) => template.id === templateId.value,

<ConfirmModal
title="Bruk møtemal"
message="Du vil overskrive dine nåværende endringer"
onConfirm={() => {
const template = allMeetingTemplates.find(
(t) => t.id === selectedTemplate,
);

if (selectedTemplate) {
form.change('title', selectedTemplate.name);
form.change('report', selectedTemplate.report);
if (template) {
form.change('title', template.name);
form.change('report', template.report);
form.change('startTime', template.startTime);
form.change('endTime', template.endTime);
form.change(
'reportAuthor',
template.reportAuthor && {
value: template.reportAuthor.username,
label: template.reportAuthor.fullName,
id: template.reportAuthor.id,
},
);

form.change(
'users',
template?.invitedUsers.map((user) => ({
value: user.username,
label: user.fullName,
id: user.id,
})),
);
form.change(
'groups',
template?.invitedGroups.map((group) => ({
value: group.id,
label: group.name,
id: group.id,
})),
);
if (template.mazemapPoi) {
form.change('mazemapPoi', template.mazemapPoi);
} else {
form.change('useMazemap', false);
form.change('location', template.location);
}
setMeetingRefreshkey((prev) => prev + 1);
}
}}
/>
closeOnConfirm
>
{({ openConfirmModal }) => (
<Field
name="template"
label="Velg en møtemal"
placeholder="Velg møtemal"
component={SelectInput.Field}
options={allMeetingTemplates.map((template) => ({
label: template.name,
value: template.id,
}))}
isSearchable={false}
onChange={(selectedOption) => {
setSelectedTemplate(selectedOption.value);
openConfirmModal();
}}
/>
)}
</ConfirmModal>

<Field
name="description"
Expand Down Expand Up @@ -473,7 +520,37 @@ const MeetingEditor = () => {
onPress={() => {
const report = form.getFieldState('report')?.value;
const name = form.getFieldState('title')?.value;
dispatch(createMeetingTemplate({ name, report }));
const location = form.getFieldState('location')?.value;
const startTime = form.getFieldState('startTime')?.value;
const endTime = form.getFieldState('endTime')?.value;
const description =
form.getFieldState('description')?.value;
const mazemapPoi = form.getFieldState('mazemapPoi')?.value;
const reportAuthor =
form.getFieldState('reportAuthor')?.value?.id;

const invitedUsers = form
.getFieldState('users')
?.value?.map((user) => user.id);

const invitedGroups = form
.getFieldState('groups')
?.value?.map((group) => group.id);

dispatch(
createMeetingTemplate({
name,
report,
location,
startTime,
endTime,
description,
mazemapPoi,
reportAuthor,
invitedUsers,
invitedGroups,
}),
);
}}
>
Lagre som møtemal
Expand Down

0 comments on commit ab2a3b4

Please sign in to comment.