2020-07-22 10:54:15 +00:00
|
|
|
import { AppErrorFragment } from "@saleor/apps/types/AppErrorFragment";
|
2019-09-26 15:33:44 +00:00
|
|
|
import AccountPermissions from "@saleor/components/AccountPermissions";
|
|
|
|
import AppHeader from "@saleor/components/AppHeader";
|
2020-07-22 10:54:15 +00:00
|
|
|
import AppStatus from "@saleor/components/AppStatus";
|
2019-09-26 15:33:44 +00:00
|
|
|
import CardSpacer from "@saleor/components/CardSpacer";
|
|
|
|
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
|
|
|
import Container from "@saleor/components/Container";
|
|
|
|
import Form from "@saleor/components/Form";
|
|
|
|
import Grid from "@saleor/components/Grid";
|
|
|
|
import PageHeader from "@saleor/components/PageHeader";
|
|
|
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
|
|
|
import { ShopInfo_shop_permissions } from "@saleor/components/Shop/types/ShopInfo";
|
|
|
|
import { sectionNames } from "@saleor/intl";
|
|
|
|
import { PermissionEnum } from "@saleor/types/globalTypes";
|
2020-04-23 15:43:08 +00:00
|
|
|
import { getFormErrors } from "@saleor/utils/errors";
|
2020-07-22 10:54:15 +00:00
|
|
|
import getAppErrorMessage from "@saleor/utils/errors/app";
|
|
|
|
import WebhooksList from "@saleor/webhooks/components/WebhooksList";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
import { AppUpdate_appUpdate_app } from "../../types/AppUpdate";
|
|
|
|
import CustomAppDefaultToken from "../CustomAppDefaultToken";
|
|
|
|
import CustomAppInformation from "../CustomAppInformation";
|
|
|
|
import CustomAppTokens from "../CustomAppTokens";
|
2019-09-26 15:33:44 +00:00
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
export interface CustomAppDetailsPageFormData {
|
2019-09-26 15:33:44 +00:00
|
|
|
hasFullAccess: boolean;
|
|
|
|
isActive: boolean;
|
|
|
|
name: string;
|
|
|
|
permissions: PermissionEnum[];
|
|
|
|
}
|
2020-07-22 10:54:15 +00:00
|
|
|
export interface CustomAppDetailsPageProps {
|
2019-10-04 10:57:40 +00:00
|
|
|
apiUri: string;
|
2019-09-26 15:33:44 +00:00
|
|
|
disabled: boolean;
|
2020-07-22 10:54:15 +00:00
|
|
|
errors: AppErrorFragment[];
|
2019-09-26 15:33:44 +00:00
|
|
|
permissions: ShopInfo_shop_permissions[];
|
|
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
2020-07-22 10:54:15 +00:00
|
|
|
app: AppUpdate_appUpdate_app;
|
2019-09-30 16:46:48 +00:00
|
|
|
token: string;
|
2019-10-04 10:57:40 +00:00
|
|
|
onApiUriClick: () => void;
|
2019-09-26 15:33:44 +00:00
|
|
|
onBack: () => void;
|
|
|
|
onTokenDelete: (id: string) => void;
|
2019-09-30 16:46:48 +00:00
|
|
|
onTokenClose: () => void;
|
2019-09-26 15:33:44 +00:00
|
|
|
onTokenCreate: () => void;
|
2020-10-22 11:33:29 +00:00
|
|
|
onSubmit: (data: CustomAppDetailsPageFormData) => Promise<any>;
|
2020-07-22 10:54:15 +00:00
|
|
|
onWebhookCreate: () => void;
|
|
|
|
onWebhookRemove: (id: string) => void;
|
|
|
|
navigateToWebhookDetails: (id: string) => () => void;
|
2019-09-26 15:33:44 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
const CustomAppDetailsPage: React.FC<CustomAppDetailsPageProps> = props => {
|
2019-09-26 15:33:44 +00:00
|
|
|
const {
|
2019-10-04 10:57:40 +00:00
|
|
|
apiUri,
|
2019-09-26 15:33:44 +00:00
|
|
|
disabled,
|
2020-02-24 14:14:48 +00:00
|
|
|
errors,
|
2019-09-26 15:33:44 +00:00
|
|
|
permissions,
|
|
|
|
saveButtonBarState,
|
2020-07-22 10:54:15 +00:00
|
|
|
app,
|
|
|
|
navigateToWebhookDetails,
|
2019-09-30 16:46:48 +00:00
|
|
|
token,
|
2019-10-04 10:57:40 +00:00
|
|
|
onApiUriClick,
|
2019-09-26 15:33:44 +00:00
|
|
|
onBack,
|
2019-09-30 16:46:48 +00:00
|
|
|
onTokenClose,
|
2019-09-26 15:33:44 +00:00
|
|
|
onTokenCreate,
|
|
|
|
onTokenDelete,
|
2020-07-22 10:54:15 +00:00
|
|
|
onSubmit,
|
|
|
|
onWebhookCreate,
|
|
|
|
onWebhookRemove
|
2019-09-26 15:33:44 +00:00
|
|
|
} = props;
|
|
|
|
const intl = useIntl();
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
const webhooks = app?.webhooks;
|
|
|
|
|
2020-04-23 15:43:08 +00:00
|
|
|
const formErrors = getFormErrors(["permissions"], errors || []);
|
2020-07-22 10:54:15 +00:00
|
|
|
const permissionsError = getAppErrorMessage(formErrors.permissions, intl);
|
2020-04-23 15:43:08 +00:00
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
const initialForm: CustomAppDetailsPageFormData = {
|
|
|
|
hasFullAccess:
|
|
|
|
permissions?.filter(
|
|
|
|
perm =>
|
|
|
|
app?.permissions?.filter(userPerm => userPerm.code === perm.code)
|
|
|
|
.length === 0
|
|
|
|
).length === 0 || false,
|
|
|
|
isActive: !!app?.isActive,
|
|
|
|
name: app?.name || "",
|
|
|
|
permissions: app?.permissions?.map(perm => perm.code) || []
|
2019-09-26 15:33:44 +00:00
|
|
|
};
|
2020-07-22 10:54:15 +00:00
|
|
|
|
2019-09-26 15:33:44 +00:00
|
|
|
return (
|
2020-02-24 14:14:48 +00:00
|
|
|
<Form initial={initialForm} onSubmit={onSubmit} confirmLeave>
|
|
|
|
{({ data, change, hasChanged, submit }) => (
|
2019-09-26 15:33:44 +00:00
|
|
|
<Container>
|
|
|
|
<AppHeader onBack={onBack}>
|
2020-07-22 10:54:15 +00:00
|
|
|
{intl.formatMessage(sectionNames.apps)}
|
2019-09-26 15:33:44 +00:00
|
|
|
</AppHeader>
|
2020-07-22 10:54:15 +00:00
|
|
|
<PageHeader title={app?.name} />
|
2019-09-26 15:33:44 +00:00
|
|
|
<Grid>
|
|
|
|
<div>
|
2019-09-30 16:46:48 +00:00
|
|
|
{token && (
|
|
|
|
<>
|
2020-07-22 10:54:15 +00:00
|
|
|
<CustomAppDefaultToken
|
2019-10-04 10:57:40 +00:00
|
|
|
apiUri={apiUri}
|
2019-09-30 16:46:48 +00:00
|
|
|
token={token}
|
2019-10-04 10:57:40 +00:00
|
|
|
onApiUriClick={onApiUriClick}
|
2019-09-30 16:46:48 +00:00
|
|
|
onTokenClose={onTokenClose}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
</>
|
|
|
|
)}
|
2020-07-22 10:54:15 +00:00
|
|
|
<CustomAppInformation
|
2019-09-26 15:33:44 +00:00
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
errors={errors}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
2020-07-22 10:54:15 +00:00
|
|
|
<CustomAppTokens
|
|
|
|
tokens={app?.tokens}
|
2019-09-26 15:33:44 +00:00
|
|
|
onCreate={onTokenCreate}
|
|
|
|
onDelete={onTokenDelete}
|
|
|
|
/>
|
2020-07-22 10:54:15 +00:00
|
|
|
<CardSpacer />
|
|
|
|
<WebhooksList
|
|
|
|
webhooks={webhooks}
|
|
|
|
onRemove={onWebhookRemove}
|
|
|
|
onRowClick={navigateToWebhookDetails}
|
|
|
|
onCreate={app?.isActive && onWebhookCreate}
|
|
|
|
/>
|
2019-09-26 15:33:44 +00:00
|
|
|
</div>
|
2019-09-27 12:21:38 +00:00
|
|
|
<div>
|
|
|
|
<AccountPermissions
|
|
|
|
data={data}
|
2020-04-23 15:43:08 +00:00
|
|
|
errorMessage={permissionsError}
|
2019-09-27 12:21:38 +00:00
|
|
|
disabled={disabled}
|
|
|
|
permissions={permissions}
|
2020-04-23 15:43:08 +00:00
|
|
|
permissionsExceeded={false}
|
2019-09-27 12:21:38 +00:00
|
|
|
onChange={change}
|
2020-04-23 15:43:08 +00:00
|
|
|
fullAccessLabel={intl.formatMessage({
|
2020-07-22 10:54:15 +00:00
|
|
|
defaultMessage: "Grant this app full access to the store",
|
2020-04-23 15:43:08 +00:00
|
|
|
description: "checkbox label"
|
|
|
|
})}
|
|
|
|
description={intl.formatMessage({
|
|
|
|
defaultMessage:
|
2020-07-22 10:54:15 +00:00
|
|
|
"Expand or restrict app permissions to access certain part of Saleor system.",
|
2020-04-23 15:43:08 +00:00
|
|
|
description: "card description"
|
|
|
|
})}
|
2019-09-27 12:21:38 +00:00
|
|
|
/>
|
|
|
|
<CardSpacer />
|
2020-07-22 10:54:15 +00:00
|
|
|
<AppStatus
|
2019-09-27 12:21:38 +00:00
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
2019-10-04 10:57:40 +00:00
|
|
|
label={intl.formatMessage({
|
2020-07-22 10:54:15 +00:00
|
|
|
defaultMessage: "App is active",
|
2019-10-04 10:57:40 +00:00
|
|
|
description: "checkbox label"
|
|
|
|
})}
|
2019-09-27 12:21:38 +00:00
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-09-26 15:33:44 +00:00
|
|
|
</Grid>
|
|
|
|
<SaveButtonBar
|
|
|
|
disabled={disabled || !hasChanged}
|
|
|
|
state={saveButtonBarState}
|
|
|
|
onCancel={onBack}
|
|
|
|
onSave={submit}
|
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
)}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
CustomAppDetailsPage.displayName = "CustomAppDetailsPage";
|
|
|
|
export default CustomAppDetailsPage;
|