@@ -2,18 +2,35 @@ import { FC } from 'react';
2
2
import { useRouteLoaderData } from 'react-router-dom' ;
3
3
import { useTranslation } from 'react-i18next' ;
4
4
import { TProject } from '@ovh-ux/manager-pci-common' ;
5
- import { FormField , FormFieldLabel , Input , Text } from '@ovhcloud/ods-react' ;
6
- import { FormProvider , useForm } from 'react-hook-form' ;
5
+ import {
6
+ Input ,
7
+ Quantity ,
8
+ QuantityControl ,
9
+ QuantityInput ,
10
+ FormField ,
11
+ FormFieldLabel ,
12
+ Text ,
13
+ } from '@ovhcloud/ods-react' ;
14
+ import { FormProvider , useForm , Controller } from 'react-hook-form' ;
7
15
import { z } from 'zod' ;
8
16
import { zodResolver } from '@hookform/resolvers/zod' ;
9
17
import clsx from 'clsx' ;
10
18
import { Breadcrumb } from '@/components/breadcrumb/Breadcrumb.component' ;
11
19
import { Cart } from '@/components/cart/Cart' ;
12
20
import { instanceNameRegex } from '@/constants' ;
13
21
22
+ const quantityRules = {
23
+ min : 1 ,
24
+ max : 5 ,
25
+ } ;
26
+
14
27
export type TInstanceCreationForm = z . infer < typeof instanceCreationSchema > ;
15
28
export const instanceCreationSchema = z . object ( {
16
29
name : z . string ( ) . regex ( instanceNameRegex ) ,
30
+ quantity : z
31
+ . number ( )
32
+ . min ( quantityRules . min )
33
+ . max ( quantityRules . max ) ,
17
34
} ) ;
18
35
19
36
const CreateInstance : FC = ( ) => {
@@ -24,12 +41,13 @@ const CreateInstance: FC = () => {
24
41
resolver : zodResolver ( instanceCreationSchema ) ,
25
42
defaultValues : {
26
43
name : 'default name to add' ,
44
+ quantity : 1 ,
27
45
} ,
28
46
mode : 'onChange' ,
29
47
} ) ;
30
48
31
49
const {
32
- formState : { errors } ,
50
+ formState : { errors, defaultValues } ,
33
51
register,
34
52
} = formMethods ;
35
53
@@ -52,7 +70,7 @@ const CreateInstance: FC = () => {
52
70
< FormProvider { ...formMethods } >
53
71
< div className = "flex gap-6" >
54
72
< section className = "w-2/3" >
55
- < section className = "mb-9" >
73
+ < article className = "mb-9" >
56
74
< Text preset = "heading-1" >
57
75
{ t ( 'common:pci_instances_common_create_instance' ) }
58
76
</ Text >
@@ -61,29 +79,86 @@ const CreateInstance: FC = () => {
61
79
eiusmod tempor incididunt ut labore et dolore magna aliqua. (Not
62
80
mandatory) Si besoin d’un texte d’introduction... .
63
81
</ Text >
64
- </ section >
65
- < section className = "w-1/2" >
66
- { /* TODO: Pre-fill name with combination of {flavor_name region_id month day hour minute} */ }
67
- < div className = "pt-3 pb-4" >
68
- < FormField >
69
- < FormFieldLabel >
70
- { t ( 'common:pci_instances_common_instance_name' ) }
71
- </ FormFieldLabel >
72
- < Input
73
- { ...register ( 'name' ) }
74
- invalid = { ! ! errors . name }
75
- className = "w-full"
76
- />
77
- </ FormField >
78
- </ div >
79
- < Text
80
- className = { clsx ( 'text-sm' , {
81
- 'text-[--ods-color-critical-500]' : ! ! errors . name ,
82
- } ) }
83
- preset = "span"
84
- >
85
- { t ( 'creation:pci_instance_creation_name_rule' ) }
82
+ </ article >
83
+ < section >
84
+ < hr className = { 'h-px my-8 bg-gray-200 border-0 w-full' } />
85
+ < Text preset = "heading-2" >
86
+ { t ( 'creation:pci_instances_creation_advanced_parameters' ) }
87
+ </ Text >
88
+ < Text preset = "paragraph" >
89
+ Lorem ipsum dolor sit amet consectetur. Tempor malesuada sit a
90
+ bibendum sit tempus pretium imperdiet
86
91
</ Text >
92
+ < hr className = { 'h-px my-8 bg-gray-200 border-0 w-full' } />
93
+ < article className = "flex flex-col w-full mb-8" >
94
+ { /* TODO: Pre-fill name with combination of {flavor_name region_id month day hour minute} */ }
95
+ < div className = "pt-3 pb-4" >
96
+ < FormField >
97
+ < FormFieldLabel >
98
+ { t ( 'common:pci_instances_common_instance_name' ) }
99
+ </ FormFieldLabel >
100
+ < Input
101
+ { ...register ( 'name' ) }
102
+ invalid = { ! ! errors . name }
103
+ className = "w-full"
104
+ />
105
+ </ FormField >
106
+ </ div >
107
+ < Text
108
+ className = { clsx ( 'text-sm' , {
109
+ 'text-[--ods-color-critical-500]' : ! ! errors . name ,
110
+ } ) }
111
+ preset = "span"
112
+ >
113
+ { t ( 'creation:pci_instance_creation_name_rule' ) }
114
+ </ Text >
115
+ </ article >
116
+ < hr className = { 'h-px my-8 bg-gray-200 border-0 w-full' } />
117
+ < article className = "flex flex-col w-full mb-8" >
118
+ < Text preset = "heading-2" >
119
+ { t ( 'creation:pci_instances_creation_quantity_title' ) }
120
+ </ Text >
121
+ < div className = "pt-3 pb-4" >
122
+ < FormField >
123
+ < FormFieldLabel >
124
+ { t ( 'creation:pci_instances_creation_quantity_label' ) }
125
+ </ FormFieldLabel >
126
+ < Controller
127
+ name = "quantity"
128
+ render = { ( { field } ) => (
129
+ < Quantity
130
+ min = { quantityRules . min }
131
+ max = { quantityRules . max }
132
+ invalid = { ! ! errors . quantity }
133
+ onValueChange = { ( { value } ) =>
134
+ field . onChange ( Number ( value ) )
135
+ }
136
+ defaultValue = {
137
+ defaultValues ? String ( defaultValues . quantity ) : '1'
138
+ }
139
+ required
140
+ >
141
+ < QuantityControl >
142
+ < QuantityInput value = { field . value } />
143
+ </ QuantityControl >
144
+ </ Quantity >
145
+ ) }
146
+ />
147
+ </ FormField >
148
+ </ div >
149
+ < Text
150
+ className = { clsx ( 'text-sm' , {
151
+ 'text-[--ods-color-critical-500]' : ! ! errors . quantity ,
152
+ } ) }
153
+ preset = "span"
154
+ >
155
+ { t ( 'creation:pci_instance_creation_quantity_rule' , {
156
+ quota : 5 ,
157
+ type : 'type' ,
158
+ region : 'region' ,
159
+ } ) }
160
+ </ Text >
161
+ </ article >
87
162
</ section >
88
163
</ section >
89
164
< aside className = "min-w-[320px] w-full max-w-[640px]" >
0 commit comments