Skip to content

Commit

Permalink
chore/trigger operations btns redesign (#477)
Browse files Browse the repository at this point in the history
* updated

* delete handler

* review

* fix

* timezone 0 sign
  • Loading branch information
EduardZaydler authored Jan 23, 2024
1 parent 17d714c commit 556db51
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 169 deletions.
Binary file modified playwright/snapshots/TriggerInfo/triggerinfo--default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified playwright/snapshots/TriggerInfo/triggerinfo--not-everyday.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified playwright/snapshots/TriggerInfo/triggerinfo--witherror.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Components/ConfirmDeleteModal/ConfirmDeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface ConfirmDeleteModalProps {
message: string;
children?: React.ReactNode;
onClose: () => void;
onDelete?: () => Promise<void>;
onDelete?: () => void;
}

export const ConfirmDeleteModal = (props: ConfirmDeleteModalProps): JSX.Element => (
Expand Down
1 change: 1 addition & 0 deletions src/Components/ContactEditModal/ContactEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default class ContactEditModal extends React.Component<Props, State> {
Save and test
</Button>
<FileExport
isButton
title={`delivery channel ${contactInfo.type} ${contactInfo.value}`}
data={omitContact(contactInfo)}
>
Expand Down
12 changes: 10 additions & 2 deletions src/Components/FileExport/FileExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@ type FileExportProps = {
title: string;
data: Partial<Trigger | Subscription | Contact>;
children?: React.ReactNode;
isButton?: boolean;
};

export default function FileExport({ title, data, children }: FileExportProps): React.ReactElement {
export default function FileExport({
title,
data,
children,
isButton,
}: FileExportProps): React.ReactElement {
const handleExport = () => {
const fileData = JSON.stringify(data, undefined, 4);
const blob = new Blob([fileData], { type: "application/json" });
saveAs(blob, `${title}.json`);
};

return (
return isButton ? (
<Button use="link" onClick={handleExport} icon={<ExportIcon />}>
{children || "Export"}
</Button>
) : (
<span onClick={handleExport}>{children || "Export"}</span>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class SubscriptionEditModal extends React.Component<Props, State>
Save and test
</Button>
<FileExport
isButton
title={this.getFileName()}
data={omitSubscription(subscription)}
>
Expand Down
32 changes: 32 additions & 0 deletions src/Components/TriggerInfo/Components/LinkMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import { Link } from "@skbkontur/react-ui/components/Link";
import { MenuItem } from "@skbkontur/react-ui";

interface ILinkMenuItemProps {
link?: string;
icon?: React.ReactElement;
onClick?: () => void;
children: React.ReactElement | string;
}

export const LinkMenuItem = ({ link, icon, onClick, children }: ILinkMenuItemProps) => {
return (
<MenuItem
href={link}
component={({ href, ...rest }) => {
return (
<Link
onClick={onClick}
icon={icon}
target="_blank"
rel="noopener noreferrer"
href={href}
{...rest}
/>
);
}}
>
{children}
</MenuItem>
);
};
28 changes: 28 additions & 0 deletions src/Components/TriggerInfo/Components/ScheduleView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";
import { Schedule } from "../../../Domain/Schedule";
import { format, addMinutes, startOfDay } from "date-fns";
import { getUTCDate } from "../../../helpers/DateUtil";

export function ScheduleView(props: { data: Schedule }): React.ReactElement {
const { data } = props;
const { days, startOffset, endOffset, tzOffset } = data;

const startTime = format(addMinutes(startOfDay(getUTCDate()), startOffset), "HH:mm");

const endTime = format(addMinutes(startOfDay(getUTCDate()), endOffset), "HH:mm");

const timeZone = format(addMinutes(startOfDay(getUTCDate()), Math.abs(tzOffset)), "HH:mm");

const timeZoneSign = tzOffset < 0 ? "+" : "−";
const enabledDays = days.filter(({ enabled }) => enabled);

return (
<>
{days.length === enabledDays.length
? "Everyday"
: enabledDays.map(({ name }) => name).join(", ")}{" "}
{startTime}{endTime} (GMT {tzOffset !== 0 && timeZoneSign}
{timeZone})
</>
);
}
Loading

0 comments on commit 556db51

Please sign in to comment.