2019-09-26 15:45:57 +00:00
|
|
|
import AccountPermissions from "@saleor/components/AccountPermissions";
|
|
|
|
import Container from "@saleor/components/Container";
|
|
|
|
import Form from "@saleor/components/Form";
|
|
|
|
import Grid from "@saleor/components/Grid";
|
|
|
|
import PageHeader from "@saleor/components/PageHeader";
|
2021-07-21 08:59:52 +00:00
|
|
|
import Savebar from "@saleor/components/Savebar";
|
2019-09-26 15:45:57 +00:00
|
|
|
import { ShopInfo_shop_permissions } from "@saleor/components/Shop/types/ShopInfo";
|
2020-11-23 13:04:24 +00:00
|
|
|
import { AppErrorFragment } from "@saleor/fragments/types/AppErrorFragment";
|
2019-09-26 15:45:57 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
2022-01-28 12:34:20 +00:00
|
|
|
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
|
2021-07-21 08:59:52 +00:00
|
|
|
import { Backlink } from "@saleor/macaw-ui";
|
2019-09-26 15:45:57 +00:00
|
|
|
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";
|
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 CustomAppInformation from "../CustomAppInformation";
|
2019-09-26 15:45:57 +00:00
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
export interface CustomAppCreatePageFormData {
|
2019-09-26 15:45:57 +00:00
|
|
|
hasFullAccess: boolean;
|
|
|
|
name: string;
|
|
|
|
permissions: PermissionEnum[];
|
|
|
|
}
|
2020-07-22 10:54:15 +00:00
|
|
|
export interface CustomAppCreatePageProps {
|
2019-09-26 15:45:57 +00:00
|
|
|
disabled: boolean;
|
2020-07-22 10:54:15 +00:00
|
|
|
errors: AppErrorFragment[];
|
2019-09-26 15:45:57 +00:00
|
|
|
permissions: ShopInfo_shop_permissions[];
|
|
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
|
|
onBack: () => void;
|
2020-07-22 10:54:15 +00:00
|
|
|
onSubmit: (data: CustomAppCreatePageFormData) => void;
|
2019-09-26 15:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
const CustomAppCreatePage: React.FC<CustomAppCreatePageProps> = props => {
|
2019-09-26 15:45:57 +00:00
|
|
|
const {
|
|
|
|
disabled,
|
2020-02-24 14:14:48 +00:00
|
|
|
errors,
|
2019-09-26 15:45:57 +00:00
|
|
|
permissions,
|
|
|
|
saveButtonBarState,
|
|
|
|
onBack,
|
|
|
|
onSubmit
|
|
|
|
} = props;
|
|
|
|
const intl = useIntl();
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
const initialForm: CustomAppCreatePageFormData = {
|
2019-09-26 15:45:57 +00:00
|
|
|
hasFullAccess: false,
|
|
|
|
name: "",
|
|
|
|
permissions: []
|
|
|
|
};
|
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
|
|
|
|
2019-09-26 15:45:57 +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:45:57 +00:00
|
|
|
<Container>
|
2021-07-21 08:59:52 +00:00
|
|
|
<Backlink onClick={onBack}>
|
2020-07-22 10:54:15 +00:00
|
|
|
{intl.formatMessage(sectionNames.apps)}
|
2021-07-21 08:59:52 +00:00
|
|
|
</Backlink>
|
2019-09-26 15:45:57 +00:00
|
|
|
<PageHeader
|
|
|
|
title={intl.formatMessage({
|
2020-07-22 10:54:15 +00:00
|
|
|
defaultMessage: "Create New App",
|
2019-09-26 15:45:57 +00:00
|
|
|
description: "header"
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<Grid>
|
|
|
|
<div>
|
2020-07-22 10:54:15 +00:00
|
|
|
<CustomAppInformation
|
2019-09-26 15:45:57 +00:00
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
errors={errors}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<AccountPermissions
|
|
|
|
data={data}
|
2020-04-23 15:43:08 +00:00
|
|
|
errorMessage={permissionsError}
|
2019-09-26 15:45:57 +00:00
|
|
|
disabled={disabled}
|
|
|
|
permissions={permissions}
|
2020-04-23 15:43:08 +00:00
|
|
|
permissionsExceeded={false}
|
2019-09-26 15:45:57 +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-26 15:45:57 +00:00
|
|
|
/>
|
|
|
|
</Grid>
|
2021-07-21 08:59:52 +00:00
|
|
|
<Savebar
|
2019-09-26 15:45:57 +00:00
|
|
|
disabled={disabled || !hasChanged}
|
|
|
|
state={saveButtonBarState}
|
|
|
|
onCancel={onBack}
|
2021-07-21 08:59:52 +00:00
|
|
|
onSubmit={submit}
|
2019-09-26 15:45:57 +00:00
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
)}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
CustomAppCreatePage.displayName = "CustomAppCreatePage";
|
|
|
|
export default CustomAppCreatePage;
|