Skip to content

Commit e3f6b58

Browse files
committed
feat(web): Implement migrate forward/backward for someday events form
functionality already existed in `SomedayEventRectangle`, similar implementation now exists inside `SomedayEventForm`
1 parent 12f71e6 commit e3f6b58

File tree

5 files changed

+91
-1
lines changed

5 files changed

+91
-1
lines changed

packages/web/src/views/Calendar/components/Sidebar/SomedayTab/SomedayEvents/SomedayEventContainer/SomedayEventContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export const SomedayEventContainer = ({
8282
>
8383
<SomedayEventForm
8484
event={event}
85+
category={category}
8586
onClose={() => {
8687
actions.closeForm();
8788
actions.close();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
import styled from "styled-components";
3+
import TooltipIconButton from "@web/components/TooltipIconButton/TooltipIconButton";
4+
5+
const StyledMigrateBackwardButton = styled.div`
6+
font-size: 25px;
7+
&:hover {
8+
cursor: pointer;
9+
}
10+
`;
11+
12+
export const MigrateBackwardButton = ({
13+
onClick,
14+
tooltipText = "Migrate Backward",
15+
}: {
16+
onClick: () => void;
17+
tooltipText: string;
18+
}) => {
19+
return (
20+
<TooltipIconButton
21+
component={
22+
<StyledMigrateBackwardButton role="button">
23+
{"<"}
24+
</StyledMigrateBackwardButton>
25+
}
26+
buttonProps={{ "aria-label": tooltipText }}
27+
tooltipProps={{
28+
description: tooltipText,
29+
onClick,
30+
}}
31+
/>
32+
);
33+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
import styled from "styled-components";
3+
import TooltipIconButton from "@web/components/TooltipIconButton/TooltipIconButton";
4+
5+
const StyledMigrateForwardButton = styled.div`
6+
font-size: 25px;
7+
&:hover {
8+
cursor: pointer;
9+
}
10+
`;
11+
12+
export const MigrateForwardButton = ({
13+
onClick,
14+
tooltipText = "Migrate Forward",
15+
}: {
16+
onClick: () => void;
17+
tooltipText: string;
18+
}) => {
19+
return (
20+
<TooltipIconButton
21+
component={
22+
<StyledMigrateForwardButton role="button">
23+
{">"}
24+
</StyledMigrateForwardButton>
25+
}
26+
buttonProps={{ "aria-label": tooltipText }}
27+
tooltipProps={{
28+
description: tooltipText,
29+
onClick,
30+
}}
31+
/>
32+
);
33+
};

packages/web/src/views/Forms/EventForm/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { SetStateAction } from "react";
22
import { Priority } from "@core/constants/core.constants";
3-
import { Schema_Event } from "@core/types/event.types";
3+
import { Categories_Event, Schema_Event } from "@core/types/event.types";
44

55
export interface FormProps {
66
event: Schema_Event;
7+
category: Categories_Event;
78
isOpen?: boolean;
89
onClose: () => void;
910
onCloseEventForm?: () => void;

packages/web/src/views/Forms/SomedayEventForm/SomedayEventForm.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { OptionsOrDependencyArray } from "react-hotkeys-hook/dist/types";
44
import { toast } from "react-toastify";
55
import "react-toastify/dist/ReactToastify.css";
66
import { Key } from "ts-key-enum";
7+
import { Categories_Event } from "@core/types/event.types";
78
import { ID_SOMEDAY_EVENT_FORM } from "@web/common/constants/web.constants";
89
import { colorByPriority } from "@web/common/styles/theme.util";
910
import {
@@ -13,6 +14,7 @@ import {
1314
import { getSomedayEventsSlice } from "@web/ducks/events/slices/someday.slice";
1415
import { useAppDispatch } from "@web/store/store.hooks";
1516
import { useDraftContext } from "@web/views/Calendar/components/Draft/context/useDraftContext";
17+
import { useSidebarContext } from "@web/views/Calendar/components/Draft/sidebar/context/useSidebarContext";
1618
import { DeleteButton } from "@web/views/Forms/EventForm/DeleteButton";
1719
import { DuplicateButton } from "@web/views/Forms/EventForm/DuplicateButton";
1820
import { PrioritySection } from "@web/views/Forms/EventForm/PrioritySection";
@@ -24,6 +26,8 @@ import {
2426
StyledTitle,
2527
} from "@web/views/Forms/EventForm/styled";
2628
import { FormProps, SetEventFormField } from "@web/views/Forms/EventForm/types";
29+
import { MigrateBackwardButton } from "../EventForm/MigrateBackwardButton";
30+
import { MigrateForwardButton } from "../EventForm/MigrateForwardButton";
2731
import { RepeatSection } from "../EventForm/RepeatSection";
2832

2933
const hotkeysOptions: OptionsOrDependencyArray = {
@@ -32,13 +36,19 @@ const hotkeysOptions: OptionsOrDependencyArray = {
3236

3337
export const SomedayEventForm: React.FC<FormProps> = ({
3438
event,
39+
category,
3540
onClose,
3641
onSubmit,
3742
setEvent,
3843
...props
3944
}) => {
4045
const dispatch = useAppDispatch();
4146
const { actions } = useDraftContext();
47+
const {
48+
actions: { onMigrate },
49+
} = useSidebarContext();
50+
51+
const target = category === Categories_Event.SOMEDAY_WEEK ? "week" : "month";
4252

4353
const { priority, title } = event || {};
4454
const bgColor = colorByPriority[priority];
@@ -185,6 +195,18 @@ export const SomedayEventForm: React.FC<FormProps> = ({
185195
role="form"
186196
>
187197
<StyledIconRow>
198+
<MigrateBackwardButton
199+
tooltipText={`Migrate to previous ${target}`}
200+
onClick={() => {
201+
onMigrate(event, category, "back");
202+
}}
203+
/>
204+
<MigrateForwardButton
205+
tooltipText={`Migrate to next ${target}`}
206+
onClick={() => {
207+
onMigrate(event, category, "forward");
208+
}}
209+
/>
188210
<DeleteButton onClick={onDelete} />
189211
<DuplicateButton onClick={onDuplicateEvent} />
190212
</StyledIconRow>

0 commit comments

Comments
 (0)