Skip to content

Commit

Permalink
Merge pull request #1162 from danskernesdigitalebibliotek/release/her…
Browse files Browse the repository at this point in the history
…mod-14

Hermod sprint 14
  • Loading branch information
kasperg authored May 14, 2024
2 parents 2c889c6 + 1e54cdd commit 4291024
Show file tree
Hide file tree
Showing 44 changed files with 553 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "b0c2a2f9-7b4d-4a6d-8324-13051e946c02",
"name": "Opening hours all",
"request": {
"url": "/dpl_opening_hours?branch_id=12",
"url": "/api/v1/opening_hours?branch_id=12",
"method": "GET"
},
"response": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "f17d80cb-0e88-46f5-910a-07d9b803d2c3",
"name": "Opening hours create instance",
"request": {
"url": "/dpl_opening_hours?_format=json",
"url": "/api/v1/opening_hours?_format=json",
"method": "POST"
},
"response": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "b03cdd7c-c1e0-4e35-b374-f429642e379f",
"name": "Opening hours current week",
"request": {
"url": "/dpl_opening_hours?branch_id=12&from_date=2024-03-25&to_date=2024-03-31",
"url": "/api/v1/opening_hours?branch_id=12&from_date=2024-03-25&to_date=2024-03-31",
"method": "GET"
},
"response": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "b4a3d509-efc1-409b-acfd-4eaad6d6c6e2",
"name": "Opening hours delete instance",
"request": {
"urlPathPattern": "/dpl_opening_hours/[0-9]+",
"urlPathPattern": "/api/v1/opening_hours/[0-9]+",
"method": "DELETE"
},
"response": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "104eae1e-ae10-4893-aadb-7f19ca988f1a",
"name": "Opening hours next week",
"request": {
"url": "/dpl_opening_hours?branch_id=12&from_date=2024-04-01&to_date=2024-04-07",
"url": "/api/v1/opening_hours?branch_id=12&from_date=2024-04-01&to_date=2024-04-07",
"method": "GET"
},
"response": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "6c1c831f-bec5-4c57-a4d1-322196701f1b",
"name": "Opening hours previous week",
"request": {
"url": "/dpl_opening_hours?branch_id=12&from_date=2024-03-18&to_date=2024-03-24",
"url": "/api/v1/opening_hours?branch_id=12&from_date=2024-03-18&to_date=2024-03-24",
"method": "GET"
},
"response": {
Expand Down
2 changes: 1 addition & 1 deletion orval.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default defineConfig({
},
input: {
target:
"https://raw.githubusercontent.com/danskernesdigitalebibliotek/dpl-cms/opening-hours-repeated/openapi.json",
"https://raw.githubusercontent.com/danskernesdigitalebibliotek/dpl-cms/develop/openapi.json",
converterOptions: {
indent: 2
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"prop-types": "Since we use former ddb-react components that depend on prop-types we keep this. Should be removed when usage of prop-types is deprecated."
},
"dependencies": {
"@danskernesdigitalebibliotek/dpl-design-system": "^2024.20.0-bb61928f15b180c4f46433eff9142953b76ba00c",
"@danskernesdigitalebibliotek/dpl-design-system": "^2024.20.1-dbc6110e263c0be00ca1fc8350a4cf6330ade2e0",
"@fullcalendar/core": "^6.1.11",
"@fullcalendar/daygrid": "^6.1.11",
"@fullcalendar/interaction": "^6.1.11",
Expand Down
10 changes: 5 additions & 5 deletions src/apps/opening-hours-editor/ConfirmAddRepeatedOpeningHour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const ConfirmAddRepeatedOpeningHour = ({
return (
<div
className="opening-hours-editor-form"
data-cy="cy-opening-hours-editor-confirm-add-repeated-form"
data-cy="opening-hours-editor-confirm-add-repeated-form"
>
<h2 className="opening-hours-editor-form__label">
{t("openingHoursConfirmAddRepeatedText")}
</h2>
<table
className="opening-hours-editor-form__table"
data-cy="cy-opening-hours-editor-form__table"
data-cy="opening-hours-editor-form__table"
>
<tbody>
<tr>
Expand Down Expand Up @@ -63,23 +63,23 @@ const ConfirmAddRepeatedOpeningHour = ({
</tbody>
</table>
<button
data-cy="cy-opening-hours-editor-form__cancel"
data-cy="opening-hours-editor-form__cancel"
type="button"
className="opening-hours-editor-form__cancel"
onClick={closeDialog}
>
{t("openingHoursConfirmAddRepeatedCancelText")}
</button>
<button
data-cy="cy-opening-hours-editor-form__confirm"
data-cy="opening-hours-editor-form__confirm"
type="button"
className="opening-hours-editor-form__submit"
onClick={() => {
confirmSubmit();
closeDialog();
}}
>
{t("openingHoursConfirmAddRepeatedSubmitText")}
{t("openingHoursConfirmRepeatedSubmitText")}
</button>
</div>
);
Expand Down
86 changes: 86 additions & 0 deletions src/apps/opening-hours-editor/ConfirmEditRepeatedOpeningHour.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React, { ChangeEvent, FC, useState } from "react";
import { useText } from "../../core/utils/text";

enum OptionValue {
This = "This",
All = "All"
}

type ConfirmEditRepeatedOpeningHourType = {
title: string;
confirmSubmit: (editSerie: boolean) => void;
closeDialog: () => void;
};

const ConfirmEditRepeatedOpeningHour: FC<
ConfirmEditRepeatedOpeningHourType
> = ({ confirmSubmit, closeDialog, title }) => {
const t = useText();
const options = [
{
value: OptionValue.This,
label: t("openingHoursEditEventConfirmOptionThisText"),
cy: "opening-hours-editor-form__radio-this"
},
{
value: OptionValue.All,
label: t("openingHoursEditEventConfirmOptionAllText"),
cy: "opening-hours-editor-form__radio-all"
}
];

const [selectedOption, setSelectedOption] = useState(options[0].value);

const handleRadioChange = (event: ChangeEvent<HTMLInputElement>) => {
if (
event.target.value === OptionValue.This ||
event.target.value === OptionValue.All
) {
setSelectedOption(event.target.value);
}
};

return (
<form className="opening-hours-editor-form">
<h2 className="opening-hours-editor-form__label">{title}</h2>
{options.map(({ value, label, cy }) => (
<div className="opening-hours-editor-form__radio" key={value}>
<input
data-cy={cy}
type="radio"
id={value}
value={value}
checked={selectedOption === value}
onChange={handleRadioChange}
/>
<label htmlFor={value}>{label}</label>
</div>
))}
<button
className="opening-hours-editor-form__cancel"
data-cy="opening-hours-editor-form__cancel"
type="button"
onClick={() => {
closeDialog();
setSelectedOption(options[0].value);
}}
>
{t("openingHoursConfirmAddRepeatedCancelText")}
</button>
<button
className="opening-hours-editor-form__submit"
data-cy="opening-hours-editor-form__confirm"
type="button"
onClick={(e) => {
e.preventDefault();
confirmSubmit(selectedOption === OptionValue.All);
setSelectedOption(options[0].value);
}}
>
{t("openingHoursConfirmRepeatedSubmitText")}
</button>
</form>
);
};

export default ConfirmEditRepeatedOpeningHour;
65 changes: 48 additions & 17 deletions src/apps/opening-hours-editor/DialogFormAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,42 @@ import {
} from "./helper";
import EventForm, { EventFormOnSubmitType } from "./EventForm";
import {
DplOpeningHoursCreatePOSTBody,
DplOpeningHoursCreatePOSTBodyRepetitionType
DplOpeningHoursCreatePOSTOpeningHoursInstanceBody,
DplOpeningHoursCreatePOSTOpeningHoursInstanceBodyRepetitionType
} from "../../core/dpl-cms/model";
import { OpeningHoursCategoriesType } from "./types";
import useDialog from "../../components/dialog/useDialog";
import ConfirmAddRepeatedOpeningHour from "./ConfirmAddRepeatedOpeningHour";
import Dialog from "../../components/dialog/Dialog";

type DialogFormAddProps = {
selectedEventInfo: DateSelectArg;
handleEventAdd: (event: DplOpeningHoursCreatePOSTBody) => void;
handleEventAdd: (
event: DplOpeningHoursCreatePOSTOpeningHoursInstanceBody
) => void;
closeDialog: () => void;
openingHoursCategories: OpeningHoursCategoriesType[];
};

const DialogFormAdd: React.FC<DialogFormAddProps> = ({
selectedEventInfo,
handleEventAdd,
closeDialog,
closeDialog: closeAddDialog,
openingHoursCategories
}) => {
const { dialogContent, openDialogWithContent, closeDialog, dialogRef } =
useDialog();
const calendarApi = selectedEventInfo.view.calendar;
const isDayGridMonth = selectedEventInfo.view.type === "dayGridMonth";
const isTimeGridWeek = selectedEventInfo.view.type === "timeGridWeek";

const handleSubmit: EventFormOnSubmitType = (
const handleSubmit = ({
category,
startTime,
endTime,
startDate,
repeatedEndDate
) => {
}: EventFormOnSubmitType) => {
const start = updateDateTime(selectedEventInfo.start, startTime);
const startStr = formatDateStr(start);
let end = updateDateTime(selectedEventInfo.end, endTime);
Expand Down Expand Up @@ -72,26 +80,49 @@ const DialogFormAdd: React.FC<DialogFormAddProps> = ({
...newFullCalenderEvent,
repetition: {
type: repeatedEndDate
? DplOpeningHoursCreatePOSTBodyRepetitionType.weekly
: DplOpeningHoursCreatePOSTBodyRepetitionType.none,
? DplOpeningHoursCreatePOSTOpeningHoursInstanceBodyRepetitionType.weekly
: DplOpeningHoursCreatePOSTOpeningHoursInstanceBodyRepetitionType.none,
...(repeatedEndDate
? { weekly_data: { end_date: repeatedEndDate } }
: {})
}
});

handleEventAdd(cmsEvent);
closeDialog();
if (repeatedEndDate) {
openDialogWithContent(
<ConfirmAddRepeatedOpeningHour
startDate={startDate}
category={category}
startTime={startTime}
endTime={endTime}
repeatedEndDate={new Date(repeatedEndDate)}
confirmSubmit={() => {
handleEventAdd(cmsEvent);
closeAddDialog();
}}
closeDialog={closeDialog}
/>
);
} else {
handleEventAdd(cmsEvent);
closeAddDialog();
}
};

return (
<EventForm
openingHoursCategories={openingHoursCategories}
startDate={selectedEventInfo.start}
endDate={selectedEventInfo.end}
onSubmit={handleSubmit}
isRepeatedOpeningHour
/>
<>
<EventForm
openingHoursCategories={openingHoursCategories}
startDate={selectedEventInfo.start}
endDate={selectedEventInfo.end}
onSubmit={handleSubmit}
isRepeatedOpeningHour
/>

<Dialog closeDialog={closeDialog} ref={dialogRef}>
{dialogContent}
</Dialog>
</>
);
};

Expand Down
Loading

0 comments on commit 4291024

Please sign in to comment.