Skip to content

Commit e6acd25

Browse files
committed
Consertando pagína de status
id podia estar undefined
1 parent fda6afc commit e6acd25

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/pages/StatusPage/index.tsx

+13-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
} from "./styles"
2626

2727
type RouteProps = {
28-
id: string
28+
id?: string
2929
}
3030

3131
type CreateManifestationStatusFormProps = {
@@ -54,7 +54,7 @@ const StatusPage: React.FC<RouteComponentProps<RouteProps>> = ({
5454
const form = useForm<CreateManifestationStatusFormProps>()
5555

5656
const search = useCallback(
57-
async (idOrProtocol: string) => {
57+
async (idOrProtocol: string | number) => {
5858
if (!idOrProtocol) return
5959

6060
// buscar dados da manifestação
@@ -125,7 +125,9 @@ const StatusPage: React.FC<RouteComponentProps<RouteProps>> = ({
125125

126126
// busca atráves da id da manifestação
127127
useEffect(() => {
128-
search(id)
128+
if (id) {
129+
search(id)
130+
}
129131
}, [id, search])
130132

131133
// pesquisa pelo protocolo inserido
@@ -142,6 +144,11 @@ const StatusPage: React.FC<RouteComponentProps<RouteProps>> = ({
142144
async function submitManifestationStatus(
143145
data: CreateManifestationStatusFormProps
144146
) {
147+
if (!manifestation) {
148+
toast.error("Erro inesperado, tente recarregar a página")
149+
return
150+
}
151+
145152
const formattedData = {
146153
description: data.description,
147154
status_id: data.status.value,
@@ -160,21 +167,21 @@ const StatusPage: React.FC<RouteComponentProps<RouteProps>> = ({
160167
toast.success(
161168
`Status da manifestação "${manifestation.title}" editado com sucesso`
162169
)
163-
search(id)
170+
search(manifestation.id)
164171
manifestationStatusData = manifestationStatusEditResponse.data
165172
}
166173
} else {
167174
const manifestationStatusCreateResponse = await Api.post<
168175
IManifestationStatus
169176
>({
170-
pathUrl: `/manifestation/${id}/status`,
177+
pathUrl: `/manifestation/${manifestation.id}/status`,
171178
data: formattedData,
172179
})
173180
if (manifestationStatusCreateResponse && manifestation) {
174181
toast.success(
175182
`Novo status criado para a manifestação "${manifestation.title}"`
176183
)
177-
search(id)
184+
search(manifestation.id)
178185
manifestationStatusData = manifestationStatusCreateResponse.data
179186
}
180187
}

0 commit comments

Comments
 (0)