Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
M
mydressin-front
Gestion
Activité
Membres
Labels
Programmation
Tickets
0
Tableaux des tickets
Jalons
Wiki
Jira
Code
Requêtes de fusion
2
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Service d'assistance
Analyse
Données d'analyse des chaînes de valeur
Contributor analytics
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
mydressin
mydressin-front
Validations
7479b9bc
Valider
7479b9bc
rédigé
il y a 9 mois
par
salaheddine zidani
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
save changes
parent
26d81fda
Branches
Branches contenant la validation
1 requête de fusion
!264
Refactoring Sale an Supplier Order Management module
Pipeline
#6768
en échec avec l'étape
in 31 minutes et 55 secondes
Modifications
1
Pipelines
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/shared/sections/product/add-product/MainForm.tsx
+75
-28
75 ajouts, 28 suppressions
src/shared/sections/product/add-product/MainForm.tsx
avec
75 ajouts
et
28 suppressions
src/shared/sections/product/add-product/MainForm.tsx
+
75
−
28
Voir le fichier @
7479b9bc
import
React
,
{
useMemo
,
useCallback
,
useState
,
useEffect
}
from
"
react
"
;
import
React
,
{
useMemo
,
useState
,
useEffect
}
from
"
react
"
;
import
{
useForm
,
Resolver
,
Controller
}
from
"
react-hook-form
"
;
import
{
yupResolver
}
from
"
@hookform/resolvers/yup
"
;
import
*
as
Yup
from
"
yup
"
;
import
{
Grid
}
from
"
@mui/material
"
;
import
{
useRouter
}
from
"
@/hooks
"
;
import
{
useResponsive
}
from
"
@/hooks/use-responsive
"
;
import
{
useSnackbar
}
from
"
@/shared/components/snackbar
"
;
import
FormProvider
from
"
@/shared/components/hook-form
"
;
import
ProductDetails
from
"
./ProductDetails
"
;
import
ProductProperties
from
"
./ProductProperties
"
;
...
...
@@ -23,17 +22,17 @@ import {
useAllGetProducts
,
useAddSimpleProduct
,
useUpdateProduct
,
checkUgsUnique
,
}
from
"
@/shared/api/product
"
;
import
{
paths
}
from
"
@/routes/paths
"
;
import
{
CustomProduct
}
from
"
@/shared/api/create-supplier-order
"
;
import
CustomAlert
from
"
@/shared/components/CustomAlert
"
;
import
{
logger
}
from
"
@/utils/logger
"
;
import
{
CustomProduct
}
from
"
../../supplier/supplier-orders/add-edit-SupplierOrder/order-new-edit-details
"
;
type
Props
=
{
currentProduct
?:
IProductItem
;
onClose
?:
()
=>
void
;
onAddProduct
?:
(
product
:
CustomProduct
)
=>
void
onAddProduct
?:
(
product
:
CustomProduct
)
=>
void
;
};
export
default
function
ProductNewEditForm
({
...
...
@@ -51,18 +50,33 @@ export default function ProductNewEditForm({
const
{
revalidate
}
=
useAllGetProducts
();
const
{
productMutate
}
=
useUpdateProduct
(
currentProduct
?.
id
!
);
const
[
alert
,
setAlert
]
=
useState
<
{
message
:
string
;
type
:
'
success
'
|
'
error
'
}
|
null
>
(
null
);
const
[
isCheckingUgs
,
setIsCheckingUgs
]
=
useState
(
false
);
const
NewProductSchema
=
Yup
.
object
().
shape
({
ugs
:
Yup
.
string
().
required
(
"
UGS is required
"
),
name
:
Yup
.
string
().
required
(
"
Name is required
"
),
ugs
:
Yup
.
string
()
.
required
(
"
UGS est requis
"
)
.
test
(
"
is-unique
"
,
"
UGS déjà utilisé.
"
,
async
function
(
value
)
{
const
{
currentProduct
}
=
this
.
options
.
context
as
{
currentProduct
?:
IProductItem
};
if
(
currentProduct
&&
currentProduct
.
ugs
===
value
)
{
return
true
;
}
const
isUnique
=
await
checkUgsUnique
(
value
||
""
);
return
isUnique
;
}),
name
:
Yup
.
string
().
required
(
"
Le nom est requis
"
),
regularPrice
:
Yup
.
number
()
.
required
(
"
regularPrice is required
"
)
.
min
(
0
,
"
Price cannot be negative
"
),
promoPrice
:
Yup
.
number
()
.
min
(
0
,
"
Promo price cannot be negative
"
)
.
required
(
"
Le tarif régulier est requis
"
)
.
min
(
0
,
"
Le prix ne peut pas être négatif
"
),
promoPrice
:
Yup
.
number
()
.
transform
((
value
,
originalValue
)
=>
(
originalValue
===
""
?
null
:
value
))
.
nullable
()
.
min
(
0
,
"
Le prix promo ne peut pas être négatif
"
)
.
optional
(),
description
:
Yup
.
string
().
optional
(),
shortDescription
:
Yup
.
string
().
optional
(),
draft
:
Yup
.
boolean
().
required
(
"
Draft
statu
s is
requi
red
"
),
draft
:
Yup
.
boolean
().
required
(
"
Le
statu
t de brouillon est
requi
s
"
),
publishWeb
:
Yup
.
boolean
().
optional
(),
publishLive
:
Yup
.
boolean
().
optional
(),
liveProductConfigs
:
Yup
.
object
().
shape
({
...
...
@@ -71,24 +85,23 @@ export default function ProductNewEditForm({
}),
stockWebConfig
:
Yup
.
object
().
shape
({
quantity
:
Yup
.
number
()
.
nullable
()
.
min
(
0
,
"
Web stock quantity cannot be ne
gative
"
)
.
optional
(),
.
nullable
()
.
min
(
0
,
"
La quantité en stock web ne peut pas être né
gative
"
)
.
optional
(),
isPreOrderAuthorized
:
Yup
.
string
().
optional
(),
authorizedConfig
:
Yup
.
boolean
().
optional
(),
thresholdValue
:
Yup
.
number
().
nullable
(),
}),
stockLiveConfig
:
Yup
.
object
().
shape
({
quantity
:
Yup
.
number
()
.
nullable
()
.
min
(
0
,
"
L
ive stock quantity cannot b
e n
e
gative
"
)
.
optional
(),
.
nullable
()
.
min
(
0
,
"
L
a quantité en stock live ne peut pas êtr
e n
é
gative
"
)
.
optional
(),
isPreOrderAuthorized
:
Yup
.
string
().
optional
(),
authorizedConfig
:
Yup
.
boolean
().
optional
(),
thresholdValue
:
Yup
.
number
().
nullable
(),
}),
});
const
defaultValues
=
useMemo
(
()
=>
({
...
...
@@ -104,7 +117,7 @@ export default function ProductNewEditForm({
draft
:
currentProduct
?.
draft
,
material
:
currentProduct
?.
material
||
""
,
categoryIds
:
currentProduct
?.
categoryIds
,
tagIds
:
currentProduct
?.
tagIds
,
tagIds
:
currentProduct
?.
tagIds
||
[]
,
variations
:
currentProduct
?.
variations
||
[],
regularPrice
:
currentProduct
?.
regularPrice
,
promoPrice
:
currentProduct
?.
promoPrice
,
...
...
@@ -129,7 +142,6 @@ export default function ProductNewEditForm({
authorizedConfig
:
false
,
thresholdValue
:
null
,
},
liveProductConfigs
:
currentProduct
?.
liveProductConfigs
||
{
feedStockFromWebStock
:
true
,
authorizeUpdateQuantity
:
true
,
...
...
@@ -144,6 +156,8 @@ export default function ProductNewEditForm({
any
>
,
defaultValues
,
context
:
{
currentProduct
},
mode
:
"
onChange
"
,
});
const
{
...
...
@@ -152,8 +166,11 @@ export default function ProductNewEditForm({
control
,
handleSubmit
,
formState
:
{
isSubmitting
},
setError
,
clearErrors
,
}
=
methods
;
const
values
=
watch
();
useEffect
(()
=>
{
if
(
variations
.
length
>
0
)
{
methods
.
setValue
(
"
variations
"
,
variations
);
...
...
@@ -174,9 +191,38 @@ export default function ProductNewEditForm({
variations
:
currentProduct
.
variations
||
[],
});
}
},
[
currentProduct
,
reset
]);
},
[
currentProduct
,
reset
,
defaultValues
]);
const
[
alert
,
setAlert
]
=
useState
<
{
message
:
string
;
type
:
'
success
'
|
'
error
'
}
|
null
>
(
null
);
const
ugsValue
=
watch
(
"
ugs
"
);
useEffect
(()
=>
{
if
(
ugsValue
===
undefined
)
return
;
const
handler
=
setTimeout
(
async
()
=>
{
if
(
ugsValue
)
{
if
(
isEditing
&&
currentProduct
&&
currentProduct
.
ugs
===
ugsValue
)
{
clearErrors
(
"
ugs
"
);
setIsCheckingUgs
(
false
);
return
;
}
setIsCheckingUgs
(
true
);
const
isUnique
=
await
checkUgsUnique
(
ugsValue
);
setIsCheckingUgs
(
false
);
if
(
!
isUnique
)
{
setError
(
"
ugs
"
,
{
type
:
"
manual
"
,
message
:
"
UGS déjà utilisé.
"
,
});
}
else
{
clearErrors
(
"
ugs
"
);
}
}
},
500
);
return
()
=>
{
clearTimeout
(
handler
);
};
},
[
ugsValue
,
isEditing
,
currentProduct
,
setError
,
clearErrors
]);
const
onSubmit
=
handleSubmit
(
async
(
data
:
IProductItem
)
=>
{
try
{
...
...
@@ -226,8 +272,8 @@ export default function ProductNewEditForm({
await
onAddProduct
({
id
:
response
.
id
,
name
:
response
.
name
,
regularP
rice
:
response
.
regularPrice
!
,
isVariable
:
response
.
productType
==
ProductType
.
VARIAB
LE
,
p
rice
:
response
.
regularPrice
,
isVariable
:
response
.
productType
!
==
"
SIMP
LE
"
,
mainImagePath
:
response
.
mainImagePath
,
type
:
response
.
productType
,
quantity
:
...
...
@@ -237,10 +283,10 @@ export default function ProductNewEditForm({
(
v
:
any
)
=>
({
id
:
v
.
id
,
name
:
v
.
name
,
regularPrice
:
v
.
regularPrice
,
mainImagePath
:
v
.
mainImagePath
||
response
.
mainImagePath
,
mainImagePath
:
v
.
mainImagePath
,
regularPrice
:
v
.
regularPrice
,
quantity
:
(
v
.
stockWebConfig
?.
quantity
||
0
)
+
(
v
.
stockLiveConfig
?.
quantity
||
0
)
(
v
.
stockLiveConfig
?.
quantity
||
0
)
})
)
:
[]
});
...
...
@@ -290,6 +336,7 @@ export default function ProductNewEditForm({
setVariations
=
{
setVariations
}
currentProduct
=
{
currentProduct
}
mainImagePath
=
{
path
}
isCheckingUgs
=
{
isCheckingUgs
}
/>
<
FormActions
...
...
This diff is collapsed.
Click to expand it.
Aperçu
0%
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter