Skip to content

Commit

Permalink
feat(Consumer): use username instead of id (#742)
Browse files Browse the repository at this point in the history
* feat(Consumer): use username instead of id

* feat: remove duplicated var
  • Loading branch information
juzhiyuan authored Nov 9, 2020
1 parent 6efd492 commit 8c40e0f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion web/config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const routes = [
component: './Consumer/Create',
},
{
path: '/consumer/:id/edit',
path: '/consumer/:username/edit',
component: './Consumer/Create',
},
{
Expand Down
14 changes: 7 additions & 7 deletions web/src/pages/Consumer/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const Page: React.FC = (props) => {
const { formatMessage } = useIntl();

useEffect(() => {
const { id } = (props as any).match.params;
if (id) {
fetchItem(id).then(({ data }) => {
const { username, desc, ...rest } = data;
const { username } = (props as any).match.params;
if (username) {
fetchItem(username).then(({ data }) => {
const { desc, ...rest } = data;
form1.setFieldsValue({ username, desc });
setPlugins(rest.plugins);
});
Expand All @@ -45,12 +45,12 @@ const Page: React.FC = (props) => {

const onSubmit = () => {
const data = { ...form1.getFieldsValue(), plugins } as ConsumerModule.Entity;
const { id } = (props as any).match.params;
(id ? update(id, data) : create(data))
const { username } = (props as any).match.params;
(username ? update(username, data) : create(data))
.then(() => {
notification.success({
message: `${
id
username
? formatMessage({ id: 'component.global.edit' })
: formatMessage({ id: 'component.global.create' })
} ${formatMessage({ id: 'menu.consumer' })} ${formatMessage({
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/Consumer/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const Page: React.FC = () => {
<Button
type="primary"
style={{ marginRight: 10 }}
onClick={() => history.push(`/consumer/${record.id}/edit`)}
onClick={() => history.push(`/consumer/${record.username}/edit`)}
>
{formatMessage({ id: 'component.global.edit' })}
</Button>
Expand All @@ -62,7 +62,7 @@ const Page: React.FC = () => {
okText={formatMessage({ id: 'component.global.confirm' })}
cancelText={formatMessage({ id: 'component.global.cancel' })}
onConfirm={() => {
remove(record.id).then(() => {
remove(record.username).then(() => {
notification.success({
message: `${formatMessage({ id: 'component.global.delete' })} ${formatMessage({
id: 'menu.consumer',
Expand Down
16 changes: 0 additions & 16 deletions web/src/pages/Consumer/index.ts

This file was deleted.

10 changes: 5 additions & 5 deletions web/src/pages/Consumer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ export const fetchList = ({ current = 1, pageSize = 10, ...res }) =>
total: data.total_size,
}));

export const fetchItem = (id: string) =>
request<{ data: ConsumerModule.ResEntity }>(`/consumers/${id}`);
export const fetchItem = (username: string) =>
request<{ data: ConsumerModule.ResEntity }>(`/consumers/${username}`);

export const create = (data: ConsumerModule.Entity) =>
request('/consumers', {
method: 'POST',
data,
});

export const update = (id: string, data: ConsumerModule.Entity) =>
request(`/consumers/${id}`, {
export const update = (username: string, data: ConsumerModule.Entity) =>
request(`/consumers/${username}`, {
method: 'PUT',
data,
});

export const remove = (id: string) => request(`/consumers/${id}`, { method: 'DELETE' });
export const remove = (username: string) => request(`/consumers/${username}`, { method: 'DELETE' });

0 comments on commit 8c40e0f

Please sign in to comment.