Skip to content

Commit

Permalink
Grant & send refund in return & replace view (#4511)
Browse files Browse the repository at this point in the history
* Fix types

* Add unit prices in grant refund view

* Strict typing on ProductCard

* Add changeset

* Update schema

* Build types

* Update lockfile

* Extract messages

* (wip) basic grant refund during return

* (wip) Fix fixtures & tests

* Add changeset

* Extract messages

* Fix refunding fulfilled items (#4483)

* Add error handling

* Fix test file

* (wip) automatically send refund

* (wip) fix send refund message

* (wip) cleanup components

* (wip) various style fixes

* (wip) extract SendRefundCheckbox

* Fix handlers & dirty amount

* Merge notifications

* Fix integration test

* Extract messages

* Migrate to strict on OrderReturn view

* Add AAA in TransactionSubmitCard test

* Extract components to separate files

* Dedicated handler for shipment cost checkbox

* Extract complex tertiary line

* Extract mutations to separate hook

* Rewrite utils tests to follow AAA

* Add integration tests

* Fix strict

* Fix crashing page when single fulfilled item is returned

* Fix typo

* Squash fulfilled & unfulfilled lines for grant mutations

* Fix types

* Fix operator precedence

* Fix crashing page when single fulfilled item is returned

* Fix types

* Add test cases

* Simplify test
  • Loading branch information
Droniu authored Jan 25, 2024
1 parent 6f6e5ef commit 9077244
Show file tree
Hide file tree
Showing 45 changed files with 1,663 additions and 268 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-bags-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Grant & send refund in return & replace view
40 changes: 40 additions & 0 deletions locale/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@
"context": "header field value, header",
"string": "Value"
},
"/5csTX": {
"context": "order returned success message",
"string": "Successfully returned products and sent refund!"
},
"/5r4he": {
"context": "label for button",
"string": "Add country"
Expand Down Expand Up @@ -1281,6 +1285,10 @@
"context": "delete app",
"string": "Are you sure you want to delete this app?"
},
"6heBHt": {
"context": "tooltip, submit form",
"string": "Transaction is non-refundable. You have to send refund manually."
},
"6iw4VR": {
"context": "delete variant dialog title",
"string": "Delete Product Variants"
Expand Down Expand Up @@ -3229,6 +3237,10 @@
"context": "checkbox label",
"string": "Rest of the World"
},
"K1ycaD": {
"context": "input label",
"string": "Refund value"
},
"K8xNLe": {
"context": "products section name",
"string": "Products"
Expand Down Expand Up @@ -3262,6 +3274,10 @@
"KN7zKn": {
"string": "Error"
},
"KOqZv3": {
"context": "tooltip, submit form",
"string": "You have to grant refund first."
},
"KRqgfo": {
"string": "User is out of your permissions scope"
},
Expand Down Expand Up @@ -4655,6 +4671,10 @@
"context": "dialog header",
"string": "Approve this fulfillment"
},
"UR2wY+": {
"context": "tooltip, submit form",
"string": "Order has no transactions. You have to send refund manually."
},
"US3IPU": {
"string": "Search Engine Description"
},
Expand Down Expand Up @@ -5980,6 +6000,10 @@
"context": "volume units types",
"string": "Volume"
},
"d1PvC8": {
"context": "checkbox",
"string": "Grant refund for returned items"
},
"d68yq7": {
"string": "Delete gift cards"
},
Expand Down Expand Up @@ -6464,6 +6488,10 @@
"gzM1em": {
"string": "Add rule"
},
"h0IgEq": {
"context": "checkbox",
"string": "Automatically send granted refund"
},
"h1rPPg": {
"context": "dialog content",
"string": "Are you sure you want to delete {attributeName}?"
Expand Down Expand Up @@ -7141,6 +7169,14 @@
"context": "money",
"string": "from {money}"
},
"lXq4EE": {
"context": "checkbox",
"string": "Refund shipment: {currency} {amount}"
},
"laax5C": {
"context": "order returned success message",
"string": "Successfully returned products and granted refund!"
},
"lct0qd": {
"string": "This list shows all attributes that will be assigned to pages that have this page type assigned."
},
Expand Down Expand Up @@ -8921,6 +8957,10 @@
"yfhLcv": {
"string": "We are working on replacing plugins with apps. Read more about"
},
"ygxco/": {
"context": "tooltip, submit form",
"string": "Client has made more than one transaction. You have to send refund manually."
},
"yhv3HX": {
"context": "voucher requirements, header",
"string": "Minimum Requirements"
Expand Down
8 changes: 8 additions & 0 deletions src/fragments/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,11 @@ export const orderGrantRefundUpdateErrorFragment = gql`
}
}
`;

export const transactionRequestRefundForGrantedRefundErrorFragment = gql`
fragment TransactionRequestRefundForGrantedRefundError on TransactionRequestRefundForGrantedRefundError {
field
message
code
}
`;
1 change: 1 addition & 0 deletions src/fragments/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ export const fragmentOrderGrantedRefunds = gql`
fragment OrderGrantedRefund on OrderGrantedRefund {
id
createdAt
shippingCostsIncluded
amount {
currency
amount
Expand Down
108 changes: 106 additions & 2 deletions src/graphql/hooks.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,13 @@ export const OrderGrantRefundUpdateErrorFragmentDoc = gql`
}
}
`;
export const TransactionRequestRefundForGrantedRefundErrorFragmentDoc = gql`
fragment TransactionRequestRefundForGrantedRefundError on TransactionRequestRefundForGrantedRefundError {
field
message
code
}
`;
export const GiftCardsSettingsFragmentDoc = gql`
fragment GiftCardsSettings on GiftCardSettings {
expiryType
Expand Down Expand Up @@ -1573,6 +1580,7 @@ export const OrderGrantedRefundFragmentDoc = gql`
fragment OrderGrantedRefund on OrderGrantedRefund {
id
createdAt
shippingCostsIncluded
amount {
currency
amount
Expand Down Expand Up @@ -10225,14 +10233,15 @@ export const FulfillmentReturnProductsDocument = gql`
...OrderError
}
order {
id
...OrderDetails
}
replaceOrder {
id
}
}
}
${OrderErrorFragmentDoc}`;
${OrderErrorFragmentDoc}
${OrderDetailsFragmentDoc}`;
export type FulfillmentReturnProductsMutationFn = Apollo.MutationFunction<Types.FulfillmentReturnProductsMutation, Types.FulfillmentReturnProductsMutationVariables>;

/**
Expand Down Expand Up @@ -11164,6 +11173,9 @@ export const OrderGrantRefundAddDocument = gql`
errors {
...OrderGrantRefundCreateError
}
grantedRefund {
id
}
}
}
${OrderGrantRefundCreateErrorFragmentDoc}`;
Expand Down Expand Up @@ -11197,6 +11209,55 @@ export function useOrderGrantRefundAddMutation(baseOptions?: ApolloReactHooks.Mu
export type OrderGrantRefundAddMutationHookResult = ReturnType<typeof useOrderGrantRefundAddMutation>;
export type OrderGrantRefundAddMutationResult = Apollo.MutationResult<Types.OrderGrantRefundAddMutation>;
export type OrderGrantRefundAddMutationOptions = Apollo.BaseMutationOptions<Types.OrderGrantRefundAddMutation, Types.OrderGrantRefundAddMutationVariables>;
export const OrderGrantRefundAddWithOrderDocument = gql`
mutation OrderGrantRefundAddWithOrder($orderId: ID!, $amount: Decimal, $reason: String, $lines: [OrderGrantRefundCreateLineInput!], $grantRefundForShipping: Boolean) {
orderGrantRefundCreate(
id: $orderId
input: {amount: $amount, reason: $reason, lines: $lines, grantRefundForShipping: $grantRefundForShipping}
) {
errors {
...OrderGrantRefundCreateError
}
grantedRefund {
id
}
order {
...OrderDetails
}
}
}
${OrderGrantRefundCreateErrorFragmentDoc}
${OrderDetailsFragmentDoc}`;
export type OrderGrantRefundAddWithOrderMutationFn = Apollo.MutationFunction<Types.OrderGrantRefundAddWithOrderMutation, Types.OrderGrantRefundAddWithOrderMutationVariables>;

/**
* __useOrderGrantRefundAddWithOrderMutation__
*
* To run a mutation, you first call `useOrderGrantRefundAddWithOrderMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useOrderGrantRefundAddWithOrderMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [orderGrantRefundAddWithOrderMutation, { data, loading, error }] = useOrderGrantRefundAddWithOrderMutation({
* variables: {
* orderId: // value for 'orderId'
* amount: // value for 'amount'
* reason: // value for 'reason'
* lines: // value for 'lines'
* grantRefundForShipping: // value for 'grantRefundForShipping'
* },
* });
*/
export function useOrderGrantRefundAddWithOrderMutation(baseOptions?: ApolloReactHooks.MutationHookOptions<Types.OrderGrantRefundAddWithOrderMutation, Types.OrderGrantRefundAddWithOrderMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useMutation<Types.OrderGrantRefundAddWithOrderMutation, Types.OrderGrantRefundAddWithOrderMutationVariables>(OrderGrantRefundAddWithOrderDocument, options);
}
export type OrderGrantRefundAddWithOrderMutationHookResult = ReturnType<typeof useOrderGrantRefundAddWithOrderMutation>;
export type OrderGrantRefundAddWithOrderMutationResult = Apollo.MutationResult<Types.OrderGrantRefundAddWithOrderMutation>;
export type OrderGrantRefundAddWithOrderMutationOptions = Apollo.BaseMutationOptions<Types.OrderGrantRefundAddWithOrderMutation, Types.OrderGrantRefundAddWithOrderMutationVariables>;
export const OrderGrantRefundEditDocument = gql`
mutation OrderGrantRefundEdit($refundId: ID!, $amount: Decimal, $reason: String, $addLines: [OrderGrantRefundUpdateLineAddInput!], $removeLines: [ID!], $grantRefundForShipping: Boolean) {
orderGrantRefundUpdate(
Expand Down Expand Up @@ -11284,6 +11345,49 @@ export function useOrderSendRefundMutation(baseOptions?: ApolloReactHooks.Mutati
export type OrderSendRefundMutationHookResult = ReturnType<typeof useOrderSendRefundMutation>;
export type OrderSendRefundMutationResult = Apollo.MutationResult<Types.OrderSendRefundMutation>;
export type OrderSendRefundMutationOptions = Apollo.BaseMutationOptions<Types.OrderSendRefundMutation, Types.OrderSendRefundMutationVariables>;
export const OrderSendRefundForGrantedRefundDocument = gql`
mutation OrderSendRefundForGrantedRefund($grantedRefundId: ID!, $transactionId: ID!) {
transactionRequestRefundForGrantedRefund(
grantedRefundId: $grantedRefundId
id: $transactionId
) {
transaction {
...TransactionItem
}
errors {
...TransactionRequestRefundForGrantedRefundError
}
}
}
${TransactionItemFragmentDoc}
${TransactionRequestRefundForGrantedRefundErrorFragmentDoc}`;
export type OrderSendRefundForGrantedRefundMutationFn = Apollo.MutationFunction<Types.OrderSendRefundForGrantedRefundMutation, Types.OrderSendRefundForGrantedRefundMutationVariables>;

/**
* __useOrderSendRefundForGrantedRefundMutation__
*
* To run a mutation, you first call `useOrderSendRefundForGrantedRefundMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useOrderSendRefundForGrantedRefundMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [orderSendRefundForGrantedRefundMutation, { data, loading, error }] = useOrderSendRefundForGrantedRefundMutation({
* variables: {
* grantedRefundId: // value for 'grantedRefundId'
* transactionId: // value for 'transactionId'
* },
* });
*/
export function useOrderSendRefundForGrantedRefundMutation(baseOptions?: ApolloReactHooks.MutationHookOptions<Types.OrderSendRefundForGrantedRefundMutation, Types.OrderSendRefundForGrantedRefundMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useMutation<Types.OrderSendRefundForGrantedRefundMutation, Types.OrderSendRefundForGrantedRefundMutationVariables>(OrderSendRefundForGrantedRefundDocument, options);
}
export type OrderSendRefundForGrantedRefundMutationHookResult = ReturnType<typeof useOrderSendRefundForGrantedRefundMutation>;
export type OrderSendRefundForGrantedRefundMutationResult = Apollo.MutationResult<Types.OrderSendRefundForGrantedRefundMutation>;
export type OrderSendRefundForGrantedRefundMutationOptions = Apollo.BaseMutationOptions<Types.OrderSendRefundForGrantedRefundMutation, Types.OrderSendRefundForGrantedRefundMutationVariables>;
export const CreateManualTransactionCaptureDocument = gql`
mutation CreateManualTransactionCapture($orderId: ID!, $amount: PositiveDecimal!, $currency: String!, $description: String, $pspReference: String) {
transactionCreate(
Expand Down
Loading

0 comments on commit 9077244

Please sign in to comment.