2019-08-26 17:08:32 +00:00
|
|
|
import { WindowTitle } from "@saleor/components/WindowTitle";
|
|
|
|
import useNavigator from "@saleor/hooks/useNavigator";
|
2019-08-29 11:01:06 +00:00
|
|
|
import useNotifier from "@saleor/hooks/useNotifier";
|
|
|
|
import React from "react";
|
2019-09-02 10:31:34 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-08-30 13:10:07 +00:00
|
|
|
|
2019-08-26 17:08:32 +00:00
|
|
|
import { getMutationState, maybe } from "../../misc";
|
2019-08-27 12:36:19 +00:00
|
|
|
import PluginsDetailsPage from "../components/PluginsDetailsPage";
|
2019-08-28 14:53:57 +00:00
|
|
|
import { TypedPluginUpdate } from "../mutations";
|
2019-08-26 17:08:32 +00:00
|
|
|
import { TypedPluginsDetailsQuery } from "../queries";
|
2019-08-27 12:36:19 +00:00
|
|
|
import { pluginsListUrl, PluginsListUrlQueryParams } from "../urls";
|
2019-08-26 17:08:32 +00:00
|
|
|
|
|
|
|
export interface PluginsDetailsProps {
|
|
|
|
id: string;
|
2019-08-27 12:36:19 +00:00
|
|
|
params: PluginsListUrlQueryParams;
|
2019-08-26 17:08:32 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
export const PluginsDetails: React.FC<PluginsDetailsProps> = ({ id }) => {
|
2019-08-26 17:08:32 +00:00
|
|
|
const navigate = useNavigator();
|
2019-08-29 11:01:06 +00:00
|
|
|
const notify = useNotifier();
|
2019-08-30 13:10:07 +00:00
|
|
|
const intl = useIntl();
|
2019-08-26 17:08:32 +00:00
|
|
|
|
|
|
|
return (
|
2019-08-28 14:53:57 +00:00
|
|
|
<TypedPluginUpdate>
|
|
|
|
{(pluginUpdate, pluginUpdateOpts) => (
|
2019-08-26 17:08:32 +00:00
|
|
|
<TypedPluginsDetailsQuery variables={{ id }}>
|
|
|
|
{PluginDetails => {
|
|
|
|
const formTransitionState = getMutationState(
|
2019-08-28 14:53:57 +00:00
|
|
|
pluginUpdateOpts.called,
|
|
|
|
pluginUpdateOpts.loading,
|
|
|
|
maybe(() => pluginUpdateOpts.data.pluginUpdate.errors)
|
2019-08-26 17:08:32 +00:00
|
|
|
);
|
|
|
|
|
2019-08-29 11:01:06 +00:00
|
|
|
const formErrors = maybe(
|
|
|
|
() => pluginUpdateOpts.data.pluginUpdate.errors,
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (formErrors.length) {
|
|
|
|
formErrors.map(error => {
|
|
|
|
notify({
|
|
|
|
text: error.message
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (pluginUpdateOpts.data) {
|
|
|
|
notify({
|
2019-08-30 13:10:07 +00:00
|
|
|
text: intl.formatMessage({
|
|
|
|
defaultMessage: "Succesfully updated plugin settings",
|
|
|
|
description: "plugin success message"
|
|
|
|
})
|
2019-08-29 11:01:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-26 17:08:32 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle
|
2019-08-28 14:53:57 +00:00
|
|
|
title={maybe(() => PluginDetails.data.plugin.name)}
|
2019-08-26 17:08:32 +00:00
|
|
|
/>
|
|
|
|
<PluginsDetailsPage
|
|
|
|
disabled={PluginDetails.loading}
|
2019-08-29 11:01:06 +00:00
|
|
|
errors={formErrors}
|
2019-08-26 17:08:32 +00:00
|
|
|
saveButtonBarState={formTransitionState}
|
2019-08-28 14:53:57 +00:00
|
|
|
plugin={maybe(() => PluginDetails.data.plugin)}
|
2019-08-26 17:08:32 +00:00
|
|
|
onBack={() => navigate(pluginsListUrl())}
|
|
|
|
onSubmit={formData => {
|
2019-08-30 12:10:42 +00:00
|
|
|
const configurationInput =
|
|
|
|
formData.configuration &&
|
|
|
|
formData.configuration.map(item => {
|
2019-08-30 10:54:18 +00:00
|
|
|
return {
|
2019-08-29 11:23:23 +00:00
|
|
|
name: item.name,
|
|
|
|
value: item.value.toString()
|
2019-08-30 10:54:18 +00:00
|
|
|
};
|
2019-08-30 12:10:42 +00:00
|
|
|
});
|
2019-08-28 14:53:57 +00:00
|
|
|
pluginUpdate({
|
2019-08-26 17:08:32 +00:00
|
|
|
variables: {
|
|
|
|
id,
|
|
|
|
input: {
|
|
|
|
active: formData.active,
|
|
|
|
configuration: configurationInput
|
2019-08-29 14:16:16 +00:00
|
|
|
? configurationInput
|
|
|
|
: null
|
2019-08-26 17:08:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</TypedPluginsDetailsQuery>
|
|
|
|
)}
|
2019-08-28 14:53:57 +00:00
|
|
|
</TypedPluginUpdate>
|
2019-08-26 17:08:32 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
PluginsDetails.displayName = "PluginsDetails";
|
|
|
|
export default PluginsDetails;
|