@@ -16,7 +16,8 @@ import {
16
16
} from '@/components/ui/select' ;
17
17
import { ICreateSupply , SupplyPriority } from '@/service/supply/types' ;
18
18
import { getSupplyPriorityProps } from '@/lib/utils' ;
19
- import { SupplyServices } from '@/service' ;
19
+ import { ShelterSupplyServices , SupplyServices } from '@/service' ;
20
+ import { ICreateShelterSupply } from '@/service/shelterSupply/types' ;
20
21
21
22
const CreateSupply = ( ) => {
22
23
const navigate = useNavigate ( ) ;
@@ -31,12 +32,12 @@ const CreateSupply = () => {
31
32
handleSubmit,
32
33
setFieldValue,
33
34
values,
34
- } = useFormik < ICreateSupply > ( {
35
+ } = useFormik < ICreateSupply & Omit < ICreateShelterSupply , 'supplyId' > > ( {
35
36
initialValues : {
36
37
name : '' ,
37
- priority : SupplyPriority . UnderControl ,
38
38
supplyCategoryId : supplyCategories ?. at ( 0 ) ?. id ?? '-1' ,
39
39
shelterId,
40
+ priority : SupplyPriority . UnderControl ,
40
41
} ,
41
42
enableReinitialize : true ,
42
43
validateOnBlur : false ,
@@ -50,9 +51,14 @@ const CreateSupply = () => {
50
51
} ) ,
51
52
onSubmit : async ( values ) => {
52
53
try {
53
- await SupplyServices . create ( {
54
- ...values ,
54
+ const resp = await SupplyServices . create ( {
55
+ name : values . name ,
56
+ supplyCategoryId : values . supplyCategoryId ,
57
+ } ) ;
58
+ await ShelterSupplyServices . create ( {
59
+ supplyId : resp . data . id ,
55
60
priority : + values . priority ,
61
+ shelterId,
56
62
} ) ;
57
63
toast ( {
58
64
title : 'Item cadastrado com sucesso' ,
0 commit comments