Add permissions to shipping settings
This commit is contained in:
parent
5a17d4dc4c
commit
05ca8effd5
2 changed files with 30 additions and 9 deletions
|
@ -5,14 +5,20 @@ import AppHeader from "@saleor/components/AppHeader";
|
||||||
import Container from "@saleor/components/Container";
|
import Container from "@saleor/components/Container";
|
||||||
import Grid from "@saleor/components/Grid";
|
import Grid from "@saleor/components/Grid";
|
||||||
import PageHeader from "@saleor/components/PageHeader";
|
import PageHeader from "@saleor/components/PageHeader";
|
||||||
|
import RequirePermissions, {
|
||||||
|
hasPermissions
|
||||||
|
} from "@saleor/components/RequirePermissions";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
import { ListActions, PageListProps } from "@saleor/types";
|
import { ListActions, PageListProps, UserPermissionProps } from "@saleor/types";
|
||||||
import { WeightUnitsEnum } from "@saleor/types/globalTypes";
|
import { PermissionEnum, WeightUnitsEnum } from "@saleor/types/globalTypes";
|
||||||
import { ShippingZoneFragment } from "../../types/ShippingZoneFragment";
|
import { ShippingZoneFragment } from "../../types/ShippingZoneFragment";
|
||||||
import ShippingWeightUnitForm from "../ShippingWeightUnitForm";
|
import ShippingWeightUnitForm from "../ShippingWeightUnitForm";
|
||||||
import ShippingZonesList from "../ShippingZonesList";
|
import ShippingZonesList from "../ShippingZonesList";
|
||||||
|
|
||||||
export interface ShippingZonesListPageProps extends PageListProps, ListActions {
|
export interface ShippingZonesListPageProps
|
||||||
|
extends PageListProps,
|
||||||
|
ListActions,
|
||||||
|
UserPermissionProps {
|
||||||
defaultWeightUnit: WeightUnitsEnum;
|
defaultWeightUnit: WeightUnitsEnum;
|
||||||
shippingZones: ShippingZoneFragment[];
|
shippingZones: ShippingZoneFragment[];
|
||||||
onBack: () => void;
|
onBack: () => void;
|
||||||
|
@ -22,7 +28,14 @@ export interface ShippingZonesListPageProps extends PageListProps, ListActions {
|
||||||
|
|
||||||
const ShippingZonesListPage: React.StatelessComponent<
|
const ShippingZonesListPage: React.StatelessComponent<
|
||||||
ShippingZonesListPageProps
|
ShippingZonesListPageProps
|
||||||
> = ({ defaultWeightUnit, disabled, onBack, onSubmit, ...listProps }) => {
|
> = ({
|
||||||
|
defaultWeightUnit,
|
||||||
|
disabled,
|
||||||
|
userPermissions,
|
||||||
|
onBack,
|
||||||
|
onSubmit,
|
||||||
|
...listProps
|
||||||
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -41,11 +54,16 @@ const ShippingZonesListPage: React.StatelessComponent<
|
||||||
<ShippingZonesList disabled={disabled} {...listProps} />
|
<ShippingZonesList disabled={disabled} {...listProps} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<ShippingWeightUnitForm
|
<RequirePermissions
|
||||||
defaultWeightUnit={defaultWeightUnit}
|
userPermissions={userPermissions}
|
||||||
disabled={disabled}
|
requiredPermissions={[PermissionEnum.MANAGE_SETTINGS]}
|
||||||
onSubmit={onSubmit}
|
>
|
||||||
/>
|
<ShippingWeightUnitForm
|
||||||
|
defaultWeightUnit={defaultWeightUnit}
|
||||||
|
disabled={disabled}
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
/>
|
||||||
|
</RequirePermissions>
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
|
@ -14,6 +14,7 @@ import usePaginator, {
|
||||||
createPaginationState
|
createPaginationState
|
||||||
} from "@saleor/hooks/usePaginator";
|
} from "@saleor/hooks/usePaginator";
|
||||||
import useShop from "@saleor/hooks/useShop";
|
import useShop from "@saleor/hooks/useShop";
|
||||||
|
import useUser from "@saleor/hooks/useUser";
|
||||||
import { commonMessages } from "@saleor/intl";
|
import { commonMessages } from "@saleor/intl";
|
||||||
import { getMutationState, maybe } from "@saleor/misc";
|
import { getMutationState, maybe } from "@saleor/misc";
|
||||||
import { ListViews } from "@saleor/types";
|
import { ListViews } from "@saleor/types";
|
||||||
|
@ -45,6 +46,7 @@ export const ShippingZonesList: React.StatelessComponent<
|
||||||
const notify = useNotifier();
|
const notify = useNotifier();
|
||||||
const paginate = usePaginator();
|
const paginate = usePaginator();
|
||||||
const shop = useShop();
|
const shop = useShop();
|
||||||
|
const { user } = useUser();
|
||||||
const { isSelected, listElements, reset, toggle, toggleAll } = useBulkActions(
|
const { isSelected, listElements, reset, toggle, toggleAll } = useBulkActions(
|
||||||
params.ids
|
params.ids
|
||||||
);
|
);
|
||||||
|
@ -195,6 +197,7 @@ export const ShippingZonesList: React.StatelessComponent<
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
}
|
}
|
||||||
|
userPermissions={maybe(() => user.permissions, [])}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ActionDialog
|
<ActionDialog
|
||||||
|
|
Loading…
Reference in a new issue