Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed Visual Bug in Workflow Editor with Digests #5279

Merged
merged 8 commits into from
Mar 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { DigestUnitEnum, MonthlyTypeEnum } from '@novu/shared';

import { colors } from '@novu/design-system';
import { pluralizeTime } from '../../../../utils';
import { useStepFormPath } from '../../hooks/useStepFormPath';

const Highlight = ({ children, isHighlight }) => {
const { colorScheme } = useMantineColorScheme();
Expand Down Expand Up @@ -61,13 +60,12 @@ const sortWeekdays = (weekdays: string[]): string[] => {
return weekdays.sort((a, b) => WEEKDAYS_ORDER.indexOf(a) - WEEKDAYS_ORDER.indexOf(b));
};

export const TimedDigestWillBeSentHeader = ({ isHighlight = true }: { isHighlight?: boolean }) => {
export const TimedDigestWillBeSentHeader = ({ path, isHighlight = true }: { path: string; isHighlight?: boolean }) => {
const { watch } = useFormContext();
const stepFormPath = useStepFormPath();

const unit = watch(`${stepFormPath}.digestMetadata.timed.unit`);
const unit = watch(`${path}.digestMetadata.timed.unit`);
if (unit == DigestUnitEnum.MINUTES) {
const amount = watch(`${stepFormPath}.digestMetadata.timed.minutes.amount`);
const amount = watch(`${path}.digestMetadata.timed.minutes.amount`);

return (
<>
Expand All @@ -77,7 +75,7 @@ export const TimedDigestWillBeSentHeader = ({ isHighlight = true }: { isHighligh
}

if (unit == DigestUnitEnum.HOURS) {
const amount = watch(`${stepFormPath}.digestMetadata.timed.hours.amount`);
const amount = watch(`${path}.digestMetadata.timed.hours.amount`);

return (
<>
Expand All @@ -87,8 +85,8 @@ export const TimedDigestWillBeSentHeader = ({ isHighlight = true }: { isHighligh
}

if (unit === DigestUnitEnum.DAYS) {
const amount = watch(`${stepFormPath}.digestMetadata.timed.days.amount`);
const atTime = watch(`${stepFormPath}.digestMetadata.timed.days.atTime`);
const amount = watch(`${path}.digestMetadata.timed.days.amount`);
const atTime = watch(`${path}.digestMetadata.timed.days.atTime`);

if (amount !== '' && amount !== '1') {
return (
Expand Down Expand Up @@ -118,9 +116,9 @@ export const TimedDigestWillBeSentHeader = ({ isHighlight = true }: { isHighligh
}

if (unit === DigestUnitEnum.WEEKS) {
const amount = watch(`${stepFormPath}.digestMetadata.timed.weeks.amount`);
const atTime = watch(`${stepFormPath}.digestMetadata.timed.weeks.atTime`);
const weekDays = watch(`${stepFormPath}.digestMetadata.timed.weeks.weekDays`) || [];
const amount = watch(`${path}.digestMetadata.timed.weeks.amount`);
const atTime = watch(`${path}.digestMetadata.timed.weeks.atTime`);
const weekDays = watch(`${path}.digestMetadata.timed.weeks.weekDays`) || [];

const weekDaysString =
weekDays?.length > 2
Expand Down Expand Up @@ -162,14 +160,14 @@ export const TimedDigestWillBeSentHeader = ({ isHighlight = true }: { isHighligh
);
}

const amount = watch(`${stepFormPath}.digestMetadata.timed.months.amount`);
const monthlyType = watch(`${stepFormPath}.digestMetadata.timed.months.monthlyType`);
const atTime = watch(`${stepFormPath}.digestMetadata.timed.months.atTime`);
const monthDays = watch(`${stepFormPath}.digestMetadata.timed.months.monthDays`) || [];
const amount = watch(`${path}.digestMetadata.timed.months.amount`);
const monthlyType = watch(`${path}.digestMetadata.timed.months.monthlyType`);
const atTime = watch(`${path}.digestMetadata.timed.months.atTime`);
const monthDays = watch(`${path}.digestMetadata.timed.months.monthDays`) || [];

if (monthlyType === MonthlyTypeEnum.ON) {
const ordinal = watch(`${stepFormPath}.digestMetadata.timed.months.ordinal`);
const ordinalValue = watch(`${stepFormPath}.digestMetadata.timed.months.ordinalValue`);
const ordinal = watch(`${path}.digestMetadata.timed.months.ordinal`);
const ordinalValue = watch(`${path}.digestMetadata.timed.months.ordinalValue`);

if (!ordinal || !ordinalValue) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const WillBeSentHeader = ({ path, isHighlight = true }: { path: string; i
const type = watch(`${path}.digestMetadata.type`);

if (type === DigestTypeEnum.TIMED) {
return <TimedDigestWillBeSentHeader isHighlight={isHighlight} />;
return <TimedDigestWillBeSentHeader path={path} isHighlight={isHighlight} />;
}

const unit = watch(`${path}.digestMetadata.regular.unit`);
Expand Down
Loading