Skip to content

Commit

Permalink
Support staff only voucher (#1174)
Browse files Browse the repository at this point in the history
* Support staff only voucher

* Trigger CI

* Update messages

* Update changelog
  • Loading branch information
orzechdev authored Jun 21, 2021
1 parent a0dce99 commit 4056ac3
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Paginate attribute values in filters - #1152 by @orzechdev
- Fix attribute values input display - #1156 by @orzechdev
- Fix product type translations - #1163 by @orzechdev
- Support staff only voucher - #1174 by @orzechdev

# 2.11.1

Expand Down
21 changes: 13 additions & 8 deletions locale/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3019,21 +3019,26 @@
"context": "voucher code, button",
"string": "Generate Code"
},
"src_dot_discounts_dot_components_dot_VoucherLimits_dot_2215544659": {
"src_dot_discounts_dot_components_dot_VoucherLimits_dot_applyOncePerCustomer": {
"context": "limit voucher",
"string": "Limit to one use per customer"
},
"src_dot_discounts_dot_components_dot_VoucherLimits_dot_hasUsageLimit": {
"context": "limit voucher",
"string": "Limit number of times this discount can be used in total"
},
"src_dot_discounts_dot_components_dot_VoucherLimits_dot_3459612469": {
"src_dot_discounts_dot_components_dot_VoucherLimits_dot_onlyForStaff": {
"context": "limit voucher",
"string": "Limit to one use per customer"
"string": "Limit to staff only"
},
"src_dot_discounts_dot_components_dot_VoucherLimits_dot_3751756157": {
"src_dot_discounts_dot_components_dot_VoucherLimits_dot_usageLimit": {
"context": "limit voucher",
"string": "Limit of Uses"
},
"src_dot_discounts_dot_components_dot_VoucherLimits_dot_usageLimitsTitle": {
"context": "voucher usage limit, header",
"string": "Usage Limit"
},
"src_dot_discounts_dot_components_dot_VoucherLimits_dot_557552777": {
"context": "voucher",
"string": "Limit of Uses"
},
"src_dot_discounts_dot_components_dot_VoucherListPage_dot_1112241061": {
"context": "tab name",
"string": "All Vouchers"
Expand Down
5 changes: 4 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,7 @@ type ExportError {
}

enum ExportErrorCode {
GRAPHQL_ERROR
INVALID
NOT_FOUND
REQUIRED
Expand Down Expand Up @@ -4106,7 +4107,7 @@ type Product implements Node & ObjectWithMetadata {
taxType: TaxType
attributes: [SelectedAttribute!]!
channelListings: [ProductChannelListing!]
mediaById(id: ID): ProductMedia!
mediaById(id: ID): ProductMedia
imageById(id: ID): ProductImage @deprecated(reason: "Will be removed in Saleor 4.0. Use the `mediaById` field instead.")
variants: [ProductVariant]
media: [ProductMedia!]
Expand Down Expand Up @@ -5757,6 +5758,7 @@ type Voucher implements Node {
endDate: DateTime
applyOncePerOrder: Boolean!
applyOncePerCustomer: Boolean!
onlyForStaff: Boolean!
discountValueType: DiscountValueTypeEnum!
minCheckoutItemsQuantity: Int
categories(before: String, after: String, first: Int, last: Int): CategoryCountableConnection
Expand Down Expand Up @@ -5858,6 +5860,7 @@ input VoucherInput {
countries: [String]
applyOncePerOrder: Boolean
applyOncePerCustomer: Boolean
onlyForStaff: Boolean
usageLimit: Int
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import VoucherValue from "../VoucherValue";
export interface FormData {
applyOncePerCustomer: boolean;
applyOncePerOrder: boolean;
onlyForStaff: boolean;
channelListings: ChannelVoucherData[];
code: string;
discountType: DiscountTypeEnum;
Expand Down Expand Up @@ -76,6 +77,7 @@ const VoucherCreatePage: React.FC<VoucherCreatePageProps> = ({
const initialForm: FormData = {
applyOncePerCustomer: false,
applyOncePerOrder: false,
onlyForStaff: false,
channelListings,
code: "",
discountType: DiscountTypeEnum.VALUE_FIXED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function voucherDetailsPageTab(tab: string): VoucherDetailsPageTab {
export interface VoucherDetailsPageFormData {
applyOncePerCustomer: boolean;
applyOncePerOrder: boolean;
onlyForStaff: boolean;
channelListings: ChannelVoucherData[];
code: string;
discountType: DiscountTypeEnum;
Expand Down Expand Up @@ -170,6 +171,7 @@ const VoucherDetailsPage: React.FC<VoucherDetailsPageProps> = ({
const initialForm: VoucherDetailsPageFormData = {
applyOncePerCustomer: voucher?.applyOncePerCustomer || false,
applyOncePerOrder: voucher?.applyOncePerOrder || false,
onlyForStaff: voucher?.onlyForStaff || false,
channelListings,
code: voucher?.code || "",
discountType,
Expand Down
29 changes: 11 additions & 18 deletions src/discounts/components/VoucherLimits/VoucherLimits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React from "react";
import { useIntl } from "react-intl";

import { VoucherDetailsPageFormData } from "../VoucherDetailsPage";
import messages from "./messages";

interface VoucherLimitsProps {
data: VoucherDetailsPageFormData;
Expand All @@ -28,19 +29,11 @@ const VoucherLimits = ({

return (
<Card>
<CardTitle
title={intl.formatMessage({
defaultMessage: "Usage Limit",
description: "voucher usage limit, header"
})}
/>
<CardTitle title={intl.formatMessage(messages.usageLimitsTitle)} />
<CardContent>
<ControlledCheckbox
checked={data.hasUsageLimit}
label={intl.formatMessage({
defaultMessage:
"Limit number of times this discount can be used in total"
})}
label={intl.formatMessage(messages.hasUsageLimit)}
name={"hasUsageLimit" as keyof VoucherDetailsPageFormData}
onChange={onChange}
/>
Expand All @@ -49,10 +42,7 @@ const VoucherLimits = ({
disabled={disabled}
error={!!formErrors.usageLimit}
helperText={getDiscountErrorMessage(formErrors.usageLimit, intl)}
label={intl.formatMessage({
defaultMessage: "Limit of Uses",
description: "voucher"
})}
label={intl.formatMessage(messages.usageLimit)}
name={"usageLimit" as keyof VoucherDetailsPageFormData}
value={data.usageLimit}
onChange={onChange}
Expand All @@ -65,13 +55,16 @@ const VoucherLimits = ({
)}
<ControlledCheckbox
checked={data.applyOncePerCustomer}
label={intl.formatMessage({
defaultMessage: "Limit to one use per customer",
description: "limit voucher"
})}
label={intl.formatMessage(messages.applyOncePerCustomer)}
name={"applyOncePerCustomer" as keyof VoucherDetailsPageFormData}
onChange={onChange}
/>
<ControlledCheckbox
checked={data.onlyForStaff}
label={intl.formatMessage(messages.onlyForStaff)}
name={"onlyForStaff" as keyof VoucherDetailsPageFormData}
onChange={onChange}
/>
</CardContent>
</Card>
);
Expand Down
24 changes: 24 additions & 0 deletions src/discounts/components/VoucherLimits/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineMessages } from "react-intl";

export default defineMessages({
usageLimitsTitle: {
defaultMessage: "Usage Limit",
description: "voucher usage limit, header"
},
hasUsageLimit: {
defaultMessage: "Limit number of times this discount can be used in total",
description: "limit voucher"
},
usageLimit: {
defaultMessage: "Limit of Uses",
description: "limit voucher"
},
applyOncePerCustomer: {
defaultMessage: "Limit to one use per customer",
description: "limit voucher"
},
onlyForStaff: {
defaultMessage: "Limit to staff only",
description: "limit voucher"
}
});
1 change: 1 addition & 0 deletions src/discounts/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ export const voucherDetails: VoucherDetails_voucher = {
__typename: "Voucher",
applyOncePerCustomer: false,
applyOncePerOrder: false,
onlyForStaff: false,
categories: {
__typename: "CategoryCountableConnection",
edges: [],
Expand Down
1 change: 1 addition & 0 deletions src/discounts/types/VoucherCataloguesAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export interface VoucherCataloguesAdd_voucherCataloguesAdd_voucher {
used: number;
applyOncePerOrder: boolean;
applyOncePerCustomer: boolean;
onlyForStaff: boolean;
products: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_products | null;
collections: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_collections | null;
categories: VoucherCataloguesAdd_voucherCataloguesAdd_voucher_categories | null;
Expand Down
1 change: 1 addition & 0 deletions src/discounts/types/VoucherCataloguesRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export interface VoucherCataloguesRemove_voucherCataloguesRemove_voucher {
used: number;
applyOncePerOrder: boolean;
applyOncePerCustomer: boolean;
onlyForStaff: boolean;
products: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_products | null;
collections: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_collections | null;
categories: VoucherCataloguesRemove_voucherCataloguesRemove_voucher_categories | null;
Expand Down
1 change: 1 addition & 0 deletions src/discounts/types/VoucherDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export interface VoucherDetails_voucher {
used: number;
applyOncePerOrder: boolean;
applyOncePerCustomer: boolean;
onlyForStaff: boolean;
products: VoucherDetails_voucher_products | null;
collections: VoucherDetails_voucher_collections | null;
categories: VoucherDetails_voucher_categories | null;
Expand Down
1 change: 1 addition & 0 deletions src/discounts/views/VoucherCreate/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function createHandler(
input: {
applyOncePerCustomer: formData.applyOncePerCustomer,
applyOncePerOrder: formData.applyOncePerOrder,
onlyForStaff: formData.onlyForStaff,
code: formData.code,
discountValueType:
formData.discountType === DiscountTypeEnum.VALUE_PERCENTAGE
Expand Down
1 change: 1 addition & 0 deletions src/discounts/views/VoucherDetails/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function createUpdateHandler(
input: {
applyOncePerCustomer: formData.applyOncePerCustomer,
applyOncePerOrder: formData.applyOncePerOrder,
onlyForStaff: formData.onlyForStaff,
discountValueType:
formData.discountType === DiscountTypeEnum.VALUE_PERCENTAGE
? DiscountValueTypeEnum.PERCENTAGE
Expand Down
1 change: 1 addition & 0 deletions src/fragments/discounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const voucherDetailsFragment = gql`
used
applyOncePerOrder
applyOncePerCustomer
onlyForStaff
products(after: $after, before: $before, first: $first, last: $last) {
edges {
node {
Expand Down
1 change: 1 addition & 0 deletions src/fragments/types/VoucherDetailsFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export interface VoucherDetailsFragment {
used: number;
applyOncePerOrder: boolean;
applyOncePerCustomer: boolean;
onlyForStaff: boolean;
products: VoucherDetailsFragment_products | null;
collections: VoucherDetailsFragment_collections | null;
categories: VoucherDetailsFragment_categories | null;
Expand Down
2 changes: 1 addition & 1 deletion src/products/types/ProductMediaById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ProductMediaById_product {
__typename: "Product";
id: string;
name: string;
mainImage: ProductMediaById_product_mainImage;
mainImage: ProductMediaById_product_mainImage | null;
media: ProductMediaById_product_media[] | null;
}

Expand Down
Loading

0 comments on commit 4056ac3

Please sign in to comment.