2019-09-27 10:17:23 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
|
|
|
import { WindowTitle } from "@saleor/components/WindowTitle";
|
|
|
|
import useNavigator from "@saleor/hooks/useNavigator";
|
|
|
|
import useNotifier from "@saleor/hooks/useNotifier";
|
|
|
|
import useShop from "@saleor/hooks/useShop";
|
|
|
|
import { commonMessages } from "@saleor/intl";
|
|
|
|
import { getMutationState, maybe } from "@saleor/misc";
|
|
|
|
import ServiceDetailsPage, {
|
|
|
|
ServiceDetailsPageFormData
|
|
|
|
} from "../../components/ServiceDetailsPage";
|
|
|
|
import { ServiceDetailsQuery } from "../../queries";
|
2019-09-27 12:21:38 +00:00
|
|
|
import {
|
|
|
|
serviceListUrl,
|
|
|
|
serviceUrl,
|
|
|
|
ServiceUrlDialog,
|
|
|
|
ServiceUrlQueryParams
|
|
|
|
} from "../../urls";
|
2019-09-27 10:17:23 +00:00
|
|
|
|
|
|
|
interface OrderListProps {
|
|
|
|
id: string;
|
|
|
|
params: ServiceUrlQueryParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ServiceDetails: React.StatelessComponent<OrderListProps> = ({
|
|
|
|
id,
|
|
|
|
params
|
|
|
|
}) => {
|
|
|
|
const navigate = useNavigator();
|
|
|
|
const notify = useNotifier();
|
|
|
|
const intl = useIntl();
|
|
|
|
const shop = useShop();
|
|
|
|
|
2019-09-27 12:21:38 +00:00
|
|
|
const closeModal = () =>
|
|
|
|
navigate(
|
|
|
|
serviceUrl(id, {
|
|
|
|
...params,
|
|
|
|
action: undefined,
|
|
|
|
id: undefined
|
|
|
|
}),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
const openModal = (action: ServiceUrlDialog, tokenId?: string) =>
|
|
|
|
navigate(
|
|
|
|
serviceUrl(id, {
|
|
|
|
...params,
|
|
|
|
action,
|
|
|
|
id: tokenId
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2019-09-27 10:17:23 +00:00
|
|
|
return (
|
|
|
|
<ServiceDetailsQuery
|
|
|
|
displayLoader
|
|
|
|
variables={{ id }}
|
|
|
|
require={["serviceAccount"]}
|
|
|
|
>
|
|
|
|
{({ data, loading }) => {
|
|
|
|
const onServiceUpdate = (data: ServiceUpdate) => {
|
|
|
|
if (!maybe(() => data.serviceUpdate.errors.length !== 0)) {
|
|
|
|
notify({
|
|
|
|
text: intl.formatMessage(commonMessages.savedChanges)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const onServiceDelete = (data: ServiceDelete) => {
|
|
|
|
if (!maybe(() => data.serviceDelete.errors.length !== 0)) {
|
|
|
|
notify({
|
|
|
|
text: intl.formatMessage(commonMessages.savedChanges)
|
|
|
|
});
|
|
|
|
navigate(serviceListUrl());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-27 12:21:38 +00:00
|
|
|
const handleBack = () => navigate(serviceListUrl());
|
2019-09-27 10:17:23 +00:00
|
|
|
|
|
|
|
const handleSubmit = (data: ServiceDetailsPageFormData) => undefined;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle title={maybe(() => data.serviceAccount.name)} />
|
|
|
|
<ServiceDetailsPage
|
|
|
|
disabled={loading}
|
|
|
|
errors={[]}
|
|
|
|
onBack={handleBack}
|
2019-09-27 12:21:38 +00:00
|
|
|
onDelete={() => openModal("remove")}
|
2019-09-27 10:17:23 +00:00
|
|
|
onSubmit={handleSubmit}
|
2019-09-27 12:21:38 +00:00
|
|
|
onTokenCreate={() => openModal("create-token")}
|
|
|
|
onTokenDelete={() => openModal("delete-token")}
|
2019-09-27 10:17:23 +00:00
|
|
|
permissions={maybe(() => shop.permissions)}
|
|
|
|
service={maybe(() => data.serviceAccount)}
|
|
|
|
saveButtonBarState="default"
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</ServiceDetailsQuery>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ServiceDetails;
|