Skip to content

Commit

Permalink
[DOP-22993] fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Zabilsya committed Jan 17, 2025
1 parent 8daa1ea commit 5a8a3a4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
18 changes: 11 additions & 7 deletions src/shared/ui/CronSelect/components/DynamicSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Period } from '@shared/services';
import { Select } from 'antd';
import { getOrdinalNumber } from '@shared/utils';

import classes from '../../styles.module.less';
import { DAYS_OF_MONTH_SELECT_OPTIONS, DAYS_OF_WEEK_SELECT_OPTIONS } from '../../constants';
Expand All @@ -27,13 +28,16 @@ export const DynamicSelect = ({
);
case Period.MONTH:
return (
<Select
className={classes.date}
size="large"
onChange={onChangeMonthDay}
options={DAYS_OF_MONTH_SELECT_OPTIONS}
value={monthDay}
/>
<div className={classes.month}>
<Select
className={classes.date}
size="large"
onChange={onChangeMonthDay}
options={DAYS_OF_MONTH_SELECT_OPTIONS}
value={monthDay}
/>
<span>{getOrdinalNumber(monthDay!, true)}</span>
</div>
);
default:
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/CronSelect/hooks/useCron/useCron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useCron = ({ value, onChange = () => undefined }: UseCronProps) =>
cronService.setMonthDay(dayjs().date());
break;
}
onChange(cronService.toString());
handleChange();
};

const handleChangeWeekDay = (weekDay: CronSegmentValue) => {
Expand Down
6 changes: 6 additions & 0 deletions src/shared/ui/CronSelect/styles.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
align-items: center;
gap: 8px;

.month {
display: flex;
align-items: center;
gap: 2px;
}

.period {
width: 100px;
}
Expand Down
32 changes: 20 additions & 12 deletions src/shared/utils/getOrdinalNumber/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
/**
* Util for getting number with its ordinal postfix
*
* @param value - number.
* @param value - number
* @param onlyPostfix - flag for returning only postfix without number
*
* @returns - ordinal number
*/
export const getOrdinalNumber = (value: number): string => {
const currentValue = value.toString();
const valueLastChar = Number(currentValue[currentValue.length - 1]);
if (valueLastChar === 1) {
return `${value}st`;
export const getOrdinalNumber = (value: number, onlyPostfix = false): string => {
const lastDigit = value % 10;
const twoLastDigits = value % 100;
let postfix = '';

if (lastDigit === 1 && twoLastDigits !== 11) {
postfix = 'st';
} else if (lastDigit === 2 && twoLastDigits !== 12) {
postfix = 'nd';
} else if (lastDigit === 3 && twoLastDigits !== 13) {
postfix = 'rd';
} else {
postfix = 'th';
}
if (valueLastChar === 2) {
return `${value}nd`;

if (onlyPostfix) {
return postfix;
}
if (valueLastChar === 3) {
return `${value}rd`;
}
return `${value}th`;

return `${value}${postfix}`;
};

0 comments on commit 5a8a3a4

Please sign in to comment.