Skip to content

Commit

Permalink
fix: use PATCH instead of PUT
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiran committed Dec 9, 2020
1 parent 935dd7f commit 9b7152d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
28 changes: 14 additions & 14 deletions web/src/pages/Route/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ const Page: React.FC = () => {
ref.current?.reload();
};

const handlePublishOffline = (rid: string, status: RouteModule.RouteStatus) => {
updateRouteStatus(rid, status).then(() => {
const actionName = status? formatMessage({ id: 'page.route.publish' }) : formatMessage({ id: 'page.route.offline' })
handleTableActionSuccessResponse(
`${actionName}${formatMessage({
id: 'menu.routes',
})}${formatMessage({ id: 'component.status.success' })}`,
);
});
}

const columns: ProColumns<RouteModule.ResponseBody>[] = [
{
title: formatMessage({ id: 'component.global.name' }),
Expand Down Expand Up @@ -107,13 +118,7 @@ const Page: React.FC = () => {
<Button
type="primary"
onClick={() => {
updateRouteStatus(record.id, 'publish').then(() => {
handleTableActionSuccessResponse(
`${formatMessage({ id: 'page.route.publish' })}${formatMessage({
id: 'menu.routes',
})}${formatMessage({ id: 'component.status.success' })}`,
);
});
handlePublishOffline(record.id, 1)
}}
style={{ marginRight: 10 }}
disabled={Boolean(record.status)}
Expand All @@ -123,16 +128,11 @@ const Page: React.FC = () => {
<Popconfirm
title={formatMessage({ id: 'page.route.popconfirm.title.offline' })}
onConfirm={() => {
updateRouteStatus(record.id!, 'offline').then(() => {
handleTableActionSuccessResponse(
`${formatMessage({ id: 'page.route.offline' })}${formatMessage({
id: 'menu.routes',
})}${formatMessage({ id: 'component.status.success' })}`,
);
});
handlePublishOffline(record.id, 0)
}}
okText={formatMessage({ id: 'component.global.confirm' })}
cancelText={formatMessage({ id: 'component.global.cancel' })}
disabled={Boolean(!record.status)}
>
<Button type="primary" danger disabled={Boolean(!record.status)}>
{formatMessage({ id: 'page.route.offline' })}
Expand Down
5 changes: 4 additions & 1 deletion web/src/pages/Route/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,7 @@ export const checkHostWithSSL = (hosts: string[]) =>
});

export const updateRouteStatus = (rid: string, status: RouteModule.RouteStatus) =>
request(`/routes/${rid}/${status}`, { method: 'PUT' });
request(`/routes/${rid}`, {
method: 'PATCH',
data: {status}
});
2 changes: 1 addition & 1 deletion web/src/pages/Route/typing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,5 @@ declare namespace RouteModule {
status: number;
};

type RouteStatus = 'publish' | 'offline';
type RouteStatus = 0 | 1;
}

0 comments on commit 9b7152d

Please sign in to comment.