Skip to content

Commit 08e40a0

Browse files
th-337: Remove time field from order form (#346)
* th-337: * fixes * th-337: - comment * th-337: - mock * th-337: * comment fixes * th-337: * validation error messages fix * th-333: * validation message fix
1 parent bc94df5 commit 08e40a0

File tree

6 files changed

+51
-31
lines changed

6 files changed

+51
-31
lines changed

frontend/src/pages/order/libs/components/libs/fields.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const getOrderFormFields = (
1010
): FormField<OrderCreateRequestDto>[] => [
1111
{ label: 'Name', name: 'customerName' },
1212
{ label: 'Phone', name: 'customerPhone' },
13-
{ label: 'Time', name: 'scheduledTime', type: 'date' },
1413
{
1514
label: 'Location',
1615
name: 'startPoint',

frontend/src/pages/order/libs/components/libs/helpers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import { type OrderCreateRequestDto } from '~/packages/orders/orders.js';
22

33
import { TruckCarsQuantity } from './enums.js';
44

5+
const getCurrentDate = (): string => {
6+
const currentDatetime = new Date();
7+
8+
return currentDatetime.toISOString();
9+
};
10+
511
const getCreateOrderDefaultPayload = (
612
selectedTruckId: number,
713
): OrderCreateRequestDto => {
814
return {
915
customerName: '',
1016
customerPhone: '',
11-
scheduledTime: '',
17+
scheduledTime: getCurrentDate(),
1218
startPoint: '',
1319
endPoint: '',
1420
carsQty: TruckCarsQuantity.MIN,
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
@import "src/assets/css/vars.scss";
22

33
.formWrapper {
4+
flex-grow: 1;
45
width: 100%;
5-
max-width: 700px;
6-
height: calc(100vh - 271px);
76
padding: 20px 100px 35px;
87
overflow: auto;
98
background-color: $white;
109
border-radius: 8px;
1110
}
1211

13-
.formWrapper::-webkit-scrollbar {
14-
width: 0;
15-
}
16-
17-
.formWrapper::-webkit-scrollbar-track {
18-
background: transparent;
19-
}
20-
21-
.formWrapper::-webkit-scrollbar-thumb {
22-
background-color: transparent;
23-
border: none;
24-
}
25-
2612
.title {
2713
margin-bottom: 15px;
2814
color: $title-color;
15+
font-weight: $font-weight-bold;
2916
font-size: 20px;
3017
}

frontend/src/pages/order/styles.module.scss

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
.page {
44
display: flex;
55
height: 100%;
6-
padding: 10px 18px 10px 47px;
6+
padding: 10px 20px;
77
overflow: hidden;
88
}
99

1010
.left {
11-
width: 35%;
12-
height: inherit;
11+
display: flex;
12+
flex-flow: column;
13+
width: 50%;
1314
margin-right: 15px;
1415
}
1516

1617
.right {
17-
width: 65%;
18+
width: 50%;
1819
height: inherit;
1920
border: 5px solid $white;
2021
border-radius: 10px;

shared/src/packages/orders/libs/enums/orders-validation-message.enum.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const OrdersValidationMessage = {
55
DRIVER_ID_MUST_BE_NUMBER: 'Orders driverId must be number',
66
TRUCK_ID_MUST_BE_NUMBER: 'Orders truckId must be number',
77
CARS_QTY_MUST_BE_NUMBER: 'Orders carsQty must be number',
8+
FIELD_IS_REQUIRED: 'This field is mandatory',
9+
NAME_NOT_VALID: 'Must be 1 - 40 characters, start with a letter, no digits',
10+
PHONE_NOT_VALID: 'Must be 7 - 18 digits, start with +',
811
} as const;
912

1013
export { OrdersValidationMessage };

shared/src/packages/orders/libs/validation-schemas/order-create-request-body.validation-schema.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,45 @@ import joi from 'joi';
33
import { positiveRequiredIntegerSchema } from '~/libs/validation-schemas/validation-schemas.js';
44
import { UserValidationRule } from '~/packages/users/libs/validation-schemas/enums/enums.js';
55

6-
import { OrdersValidationMessage } from '../enums/orders-validation-message.enum.js';
6+
import { OrdersValidationMessage as Message } from '../enums/orders-validation-message.enum.js';
77
import { type OrderCreateRequestDto } from '../types/types.js';
88

99
const orderCreateRequestBody = joi.object<OrderCreateRequestDto, true>({
10-
scheduledTime: joi.string().isoDate().required(),
10+
scheduledTime: joi.string().isoDate().required().messages({
11+
'string.empty': Message.FIELD_IS_REQUIRED,
12+
}),
1113
carsQty: positiveRequiredIntegerSchema(
12-
OrdersValidationMessage.CARS_QTY_MUST_BE_NUMBER,
13-
),
14-
startPoint: joi.string().required(),
15-
endPoint: joi.string().required(),
14+
Message.CARS_QTY_MUST_BE_NUMBER,
15+
).messages({
16+
'string.empty': Message.FIELD_IS_REQUIRED,
17+
}),
18+
startPoint: joi.string().required().messages({
19+
'string.empty': Message.FIELD_IS_REQUIRED,
20+
}),
21+
endPoint: joi.string().required().messages({
22+
'string.empty': Message.FIELD_IS_REQUIRED,
23+
}),
1624
truckId: positiveRequiredIntegerSchema(
17-
OrdersValidationMessage.TRUCK_ID_MUST_BE_NUMBER,
18-
),
19-
customerName: joi.string().pattern(UserValidationRule.NAME).allow(null),
20-
customerPhone: joi.string().pattern(UserValidationRule.PHONE).allow(null),
25+
Message.TRUCK_ID_MUST_BE_NUMBER,
26+
).messages({
27+
'string.empty': Message.FIELD_IS_REQUIRED,
28+
}),
29+
customerName: joi
30+
.string()
31+
.pattern(UserValidationRule.NAME)
32+
.allow(null)
33+
.messages({
34+
'string.empty': Message.FIELD_IS_REQUIRED,
35+
'string.pattern.base': Message.NAME_NOT_VALID,
36+
}),
37+
customerPhone: joi
38+
.string()
39+
.pattern(UserValidationRule.PHONE)
40+
.allow(null)
41+
.messages({
42+
'string.empty': Message.FIELD_IS_REQUIRED,
43+
'string.pattern.base': Message.PHONE_NOT_VALID,
44+
}),
2145
});
2246

2347
export { orderCreateRequestBody };

0 commit comments

Comments
 (0)