@@ -25,7 +25,7 @@ import {
25
25
} from "./styles"
26
26
27
27
type RouteProps = {
28
- id : string
28
+ id ? : string
29
29
}
30
30
31
31
type CreateManifestationStatusFormProps = {
@@ -54,7 +54,7 @@ const StatusPage: React.FC<RouteComponentProps<RouteProps>> = ({
54
54
const form = useForm < CreateManifestationStatusFormProps > ( )
55
55
56
56
const search = useCallback (
57
- async ( idOrProtocol : string ) => {
57
+ async ( idOrProtocol : string | number ) => {
58
58
if ( ! idOrProtocol ) return
59
59
60
60
// buscar dados da manifestação
@@ -125,7 +125,9 @@ const StatusPage: React.FC<RouteComponentProps<RouteProps>> = ({
125
125
126
126
// busca atráves da id da manifestação
127
127
useEffect ( ( ) => {
128
- search ( id )
128
+ if ( id ) {
129
+ search ( id )
130
+ }
129
131
} , [ id , search ] )
130
132
131
133
// pesquisa pelo protocolo inserido
@@ -142,6 +144,11 @@ const StatusPage: React.FC<RouteComponentProps<RouteProps>> = ({
142
144
async function submitManifestationStatus (
143
145
data : CreateManifestationStatusFormProps
144
146
) {
147
+ if ( ! manifestation ) {
148
+ toast . error ( "Erro inesperado, tente recarregar a página" )
149
+ return
150
+ }
151
+
145
152
const formattedData = {
146
153
description : data . description ,
147
154
status_id : data . status . value ,
@@ -160,21 +167,21 @@ const StatusPage: React.FC<RouteComponentProps<RouteProps>> = ({
160
167
toast . success (
161
168
`Status da manifestação "${ manifestation . title } " editado com sucesso`
162
169
)
163
- search ( id )
170
+ search ( manifestation . id )
164
171
manifestationStatusData = manifestationStatusEditResponse . data
165
172
}
166
173
} else {
167
174
const manifestationStatusCreateResponse = await Api . post <
168
175
IManifestationStatus
169
176
> ( {
170
- pathUrl : `/manifestation/${ id } /status` ,
177
+ pathUrl : `/manifestation/${ manifestation . id } /status` ,
171
178
data : formattedData ,
172
179
} )
173
180
if ( manifestationStatusCreateResponse && manifestation ) {
174
181
toast . success (
175
182
`Novo status criado para a manifestação "${ manifestation . title } "`
176
183
)
177
- search ( id )
184
+ search ( manifestation . id )
178
185
manifestationStatusData = manifestationStatusCreateResponse . data
179
186
}
180
187
}
0 commit comments