@lookiero/checkout 7.0.0-beta.0 → 7.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/ExpoRoot.js +1 -8
- package/dist/src/infrastructure/ab-testing/kameleoonEnvironment.d.ts +2 -6
- package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.js +1 -10
- package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.style.d.ts +1 -7
- package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.style.js +1 -7
- package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/textareaReturnQuestionItem/TextareaReturnQuestionItem.js +2 -7
- package/dist/src/infrastructure/ui/routing/CheckoutMiddleware.js +5 -1
- package/dist/src/infrastructure/ui/routing/Routing.js +2 -4
- package/dist/src/infrastructure/ui/views/checkout/Checkout.js +4 -4
- package/dist/src/infrastructure/ui/views/feedback/Feedback.d.ts +2 -2
- package/dist/src/infrastructure/ui/views/item/Item.js +4 -33
- package/dist/src/infrastructure/ui/views/return/Return.js +8 -127
- package/dist/src/infrastructure/ui/views/return/components/productVariantPreview/ProductVariantPreview.js +5 -7
- package/dist/src/infrastructure/ui/views/return/components/returnQuestionsForm/ReturnQuestionsForm.d.ts +15 -0
- package/dist/src/infrastructure/ui/views/return/components/returnQuestionsForm/ReturnQuestionsForm.js +112 -0
- package/dist/src/infrastructure/ui/views/return/components/returnQuestionsForm/ReturnQuestionsForm.style.d.ts +40 -0
- package/dist/src/infrastructure/ui/views/return/components/returnQuestionsForm/ReturnQuestionsForm.style.js +43 -0
- package/dist/src/infrastructure/ui/views/summary/Summary.js +4 -4
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
- package/src/ExpoRoot.tsx +1 -8
- package/src/infrastructure/ab-testing/kameleoonEnvironment.ts +3 -7
- package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.style.ts +1 -7
- package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.test.tsx +0 -5
- package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.tsx +2 -17
- package/src/infrastructure/ui/components/organisms/returnQuestions/components/textareaReturnQuestionItem/TextareaReturnQuestionItem.test.tsx +0 -5
- package/src/infrastructure/ui/components/organisms/returnQuestions/components/textareaReturnQuestionItem/TextareaReturnQuestionItem.tsx +11 -20
- package/src/infrastructure/ui/routing/CheckoutMiddleware.test.tsx +10 -0
- package/src/infrastructure/ui/routing/CheckoutMiddleware.tsx +7 -1
- package/src/infrastructure/ui/routing/Routing.tsx +3 -6
- package/src/infrastructure/ui/views/checkout/Checkout.tsx +6 -6
- package/src/infrastructure/ui/views/feedback/Feedback.tsx +2 -2
- package/src/infrastructure/ui/views/item/Item.test.tsx +6 -62
- package/src/infrastructure/ui/views/item/Item.tsx +5 -48
- package/src/infrastructure/ui/views/return/Return.test.tsx +54 -0
- package/src/infrastructure/ui/views/return/Return.tsx +12 -200
- package/src/infrastructure/ui/views/return/components/productVariantPreview/ProductVariantPreview.test.tsx +32 -0
- package/src/infrastructure/ui/views/return/components/productVariantPreview/ProductVariantPreview.tsx +12 -7
- package/src/infrastructure/ui/views/return/components/productVariantPreview/__snapshots__/ProductVariantPreview.test.tsx.snap +221 -0
- package/src/infrastructure/ui/views/return/components/returnQuestionsForm/ReturnQuestionsForm.test.tsx +95 -0
- package/src/infrastructure/ui/views/return/components/returnQuestionsForm/ReturnQuestionsForm.tsx +184 -0
- package/src/infrastructure/ui/views/summary/Summary.tsx +6 -6
- package/src/infrastructure/ui/hooks/useNewFeedbackExperiment.test.tsx +0 -84
- package/src/infrastructure/ui/hooks/useNewFeedbackExperiment.tsx +0 -82
- package/src/infrastructure/ui/views/item/components/returnQuestionsForm/ReturnQuestionsForm.style.ts +0 -18
- package/src/infrastructure/ui/views/item/components/returnQuestionsForm/ReturnQuestionsForm.tsx +0 -79
- /package/src/infrastructure/ui/views/return/{Return.style.ts → components/returnQuestionsForm/ReturnQuestionsForm.style.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { FC, useCallback, useEffect, useMemo, useRef
|
|
1
|
+
import React, { FC, useCallback, useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import { generatePath, useMatch, useNavigate, useParams } from "react-router-native";
|
|
3
3
|
import { Box, Spinner } from "@lookiero/aurora";
|
|
4
|
-
import {
|
|
4
|
+
import { QueryStatus } from "@lookiero/messaging-react";
|
|
5
5
|
import { useLogger } from "@lookiero/sty-psp-logging";
|
|
6
6
|
import { useScreenSize } from "@lookiero/sty-psp-ui";
|
|
7
7
|
import { Layout } from "@lookiero/sty-psp-ui";
|
|
@@ -11,9 +11,7 @@ import {
|
|
|
11
11
|
ProductVariantProjection,
|
|
12
12
|
} from "../../../../projection/bookedProductsVariants/bookedProductsVariants";
|
|
13
13
|
import { CheckoutItemProjection } from "../../../../projection/checkoutItem/checkoutItem";
|
|
14
|
-
import { FeedbackProjection } from "../../../../projection/feedback/feedback";
|
|
15
14
|
import { useBookCheckoutBookingForCheckoutItem } from "../../../domain/checkoutBooking/react/useBookCheckoutBookingForCheckoutItem";
|
|
16
|
-
import { useReturnCheckoutItem } from "../../../domain/checkoutItem/react/useReturnCheckoutItem";
|
|
17
15
|
import { useViewBookedProductsVariantsForCheckoutItem } from "../../../projection/bookedProductsVariants/react/useViewBookedProductsVariantsForCheckoutItem";
|
|
18
16
|
import { useViewFirstAvailableCheckoutByCustomerId } from "../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
19
17
|
import { useViewFiveItemsDiscountByCustomerId } from "../../../projection/checkout/react/useViewFiveItemsDiscountByCustomerId";
|
|
@@ -24,17 +22,14 @@ import { useTrackItemPageView } from "../../../tracking/useTrackItemPageView";
|
|
|
24
22
|
import { useTrackPressBack } from "../../../tracking/useTrackPressBack";
|
|
25
23
|
import { useTrackPressNext } from "../../../tracking/useTrackPressNext";
|
|
26
24
|
import { useTrackPressPrevious } from "../../../tracking/useTrackPressPrevious";
|
|
27
|
-
import { useTrackReturnItem } from "../../../tracking/useTrackReturnItem";
|
|
28
25
|
import { FiveItemsDiscountBanner } from "../../components/atoms/fiveItemsDiscountBanner/FiveItemsDiscountBanner";
|
|
29
26
|
import { ReturnQuestionFeedbackProvider } from "../../components/organisms/returnQuestions/behaviors/useReturnQuestionFeedback";
|
|
30
27
|
import { ItemDetailHeader } from "../../components/templates/header/itemDetailHeader/ItemDetailHeader";
|
|
31
28
|
import { ItemHeader } from "../../components/templates/header/itemHeader/ItemHeader";
|
|
32
|
-
import { NewFeedbackExperimentVariation, useNewFeedbackExperiment } from "../../hooks/useNewFeedbackExperiment";
|
|
33
29
|
import { useStaticInfo } from "../../hooks/useStaticInfo";
|
|
34
30
|
import { Routes } from "../../routing/routes";
|
|
35
31
|
import { useBasePath } from "../../routing/useBasePath";
|
|
36
32
|
import { style } from "./Item.style";
|
|
37
|
-
import { ReturnQuestionsForm } from "./components/returnQuestionsForm/ReturnQuestionsForm";
|
|
38
33
|
import {
|
|
39
34
|
CheckoutItemWithCustomerDecission,
|
|
40
35
|
ItemWithCustomerDecission,
|
|
@@ -78,11 +73,6 @@ const Item: FC<ItemProps> = ({ layout: Layout }) => {
|
|
|
78
73
|
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
79
74
|
const checkoutItem = checkout?.items.find((checkoutItem) => checkoutItem.id === id) as CheckoutItemProjection;
|
|
80
75
|
|
|
81
|
-
/* Kameleoon experiment */
|
|
82
|
-
const newFeedbackVariation = useNewFeedbackExperiment();
|
|
83
|
-
const redirectToReturnPage = newFeedbackVariation === NewFeedbackExperimentVariation.RETURN_PAGE;
|
|
84
|
-
/* Kameleoon experiment */
|
|
85
|
-
|
|
86
76
|
/* SizeChange and Booking */
|
|
87
77
|
const [isSizeChangeEnabled, sizeChangeEnabledStatus] = useViewIsSizeChangeEnabledByCheckoutId({
|
|
88
78
|
checkoutId: checkout?.id,
|
|
@@ -111,32 +101,9 @@ const Item: FC<ItemProps> = ({ layout: Layout }) => {
|
|
|
111
101
|
const [returnQuestions] = useListReturnQuestionsByCheckoutItemId({
|
|
112
102
|
checkoutItemId: checkoutItem.id,
|
|
113
103
|
});
|
|
114
|
-
const [returnQuestionsVisible, setReturnQuestionsVisible] = useState(false);
|
|
115
|
-
const showReturnQuestions = useCallback(() => setReturnQuestionsVisible(true), []);
|
|
116
|
-
const hideReturnQuestions = useCallback(() => setReturnQuestionsVisible(false), []);
|
|
117
104
|
const goToReturnPage = useCallback(() => {
|
|
118
105
|
navigate(`${basePath}/${generatePath(Routes.RETURN, { id: checkoutItem.id })}`);
|
|
119
106
|
}, [basePath, checkoutItem.id, navigate]);
|
|
120
|
-
|
|
121
|
-
const [returnCheckoutItem, returnCheckoutItemStatus] = useReturnCheckoutItem({
|
|
122
|
-
checkoutItemId: checkoutItem.id,
|
|
123
|
-
logger,
|
|
124
|
-
});
|
|
125
|
-
const trackReturnItem = useTrackReturnItem({
|
|
126
|
-
page: TrackingPage.ITEM,
|
|
127
|
-
country,
|
|
128
|
-
segment,
|
|
129
|
-
checkoutId: checkout?.id,
|
|
130
|
-
checkoutItemId: checkoutItem.id,
|
|
131
|
-
});
|
|
132
|
-
const returnItem = useCallback(
|
|
133
|
-
async (feedbacks: FeedbackProjection) => {
|
|
134
|
-
hideReturnQuestions();
|
|
135
|
-
returnCheckoutItem({ feedbacks });
|
|
136
|
-
trackReturnItem();
|
|
137
|
-
},
|
|
138
|
-
[hideReturnQuestions, returnCheckoutItem, trackReturnItem],
|
|
139
|
-
);
|
|
140
107
|
/* ReturnCheckoutItem */
|
|
141
108
|
|
|
142
109
|
const currentProductVariant: ProductVariantProjection = useMemo(
|
|
@@ -242,8 +209,7 @@ const Item: FC<ItemProps> = ({ layout: Layout }) => {
|
|
|
242
209
|
bookedProductsVariantsStatus !== QueryStatus.LOADING &&
|
|
243
210
|
fiveItemsDiscountStatus !== QueryStatus.LOADING &&
|
|
244
211
|
sizeChangeEnabledStatus !== QueryStatus.LOADING &&
|
|
245
|
-
(isBookingRequired ? checkout.checkoutBookingId && bookedProductsVariants : true)
|
|
246
|
-
returnCheckoutItemStatus !== CommandStatus.LOADING;
|
|
212
|
+
(isBookingRequired ? checkout.checkoutBookingId && bookedProductsVariants : true);
|
|
247
213
|
|
|
248
214
|
if (!dependenciesLoaded) {
|
|
249
215
|
return <Spinner testID="spinner" />;
|
|
@@ -266,7 +232,7 @@ const Item: FC<ItemProps> = ({ layout: Layout }) => {
|
|
|
266
232
|
checkoutId={checkout.id}
|
|
267
233
|
checkoutItem={checkoutItem as CheckoutItemWithoutCustomerDecission}
|
|
268
234
|
currentProductVariant={currentProductVariant}
|
|
269
|
-
onReturn={
|
|
235
|
+
onReturn={goToReturnPage}
|
|
270
236
|
/>
|
|
271
237
|
) : (
|
|
272
238
|
<ItemWithCustomerDecission
|
|
@@ -274,19 +240,10 @@ const Item: FC<ItemProps> = ({ layout: Layout }) => {
|
|
|
274
240
|
checkoutItem={checkoutItem as CheckoutItemWithCustomerDecission}
|
|
275
241
|
currentProductVariant={currentProductVariant}
|
|
276
242
|
returnQuestions={returnQuestions}
|
|
277
|
-
onEditFeedback={
|
|
243
|
+
onEditFeedback={goToReturnPage}
|
|
278
244
|
/>
|
|
279
245
|
)}
|
|
280
246
|
</Layout>
|
|
281
|
-
|
|
282
|
-
{!redirectToReturnPage ? (
|
|
283
|
-
<ReturnQuestionsForm
|
|
284
|
-
returnQuestions={returnQuestions}
|
|
285
|
-
visible={returnQuestionsVisible}
|
|
286
|
-
onClose={hideReturnQuestions}
|
|
287
|
-
onSubmit={returnItem}
|
|
288
|
-
/>
|
|
289
|
-
) : null}
|
|
290
247
|
</ReturnQuestionFeedbackProvider>
|
|
291
248
|
);
|
|
292
249
|
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CommandStatus, QueryStatus } from "@lookiero/messaging-react";
|
|
3
|
+
import { Country } from "@lookiero/sty-psp-locale";
|
|
4
|
+
import { Segment } from "@lookiero/sty-psp-segment";
|
|
5
|
+
import { DummyLayout } from "@lookiero/sty-psp-ui";
|
|
6
|
+
import { CheckoutItemStatus } from "../../../../domain/checkoutItem/model/checkoutItem";
|
|
7
|
+
import { useReturnCheckoutItem } from "../../../domain/checkoutItem/react/useReturnCheckoutItem";
|
|
8
|
+
import { checkout } from "../../../projection/checkout/checkout.mock";
|
|
9
|
+
import { useViewFirstAvailableCheckoutByCustomerId } from "../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
10
|
+
import { useListReturnQuestionsByCheckoutItemId } from "../../../projection/returnQuestion/react/useListReturnQuestionsByCheckoutItemId";
|
|
11
|
+
import { returnQuestions as mockReturnQuestions } from "../../../projection/returnQuestion/returnQuestions.mock";
|
|
12
|
+
import { render } from "../../test/render";
|
|
13
|
+
import { Return } from "./Return";
|
|
14
|
+
|
|
15
|
+
const customerId = "a8fff6d7-708c-41a7-b42a-58c5706d33df";
|
|
16
|
+
const country = Country.ES;
|
|
17
|
+
const segment = Segment.WOMEN;
|
|
18
|
+
const mockCheckout = checkout({
|
|
19
|
+
items: [
|
|
20
|
+
{ status: CheckoutItemStatus.KEPT },
|
|
21
|
+
{ status: CheckoutItemStatus.RETURNED },
|
|
22
|
+
{ status: CheckoutItemStatus.REPLACED },
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
const mockFirstCheckoutItemId = mockCheckout.items[0]?.id;
|
|
26
|
+
|
|
27
|
+
jest.mock("../../hooks/useStaticInfo", () => ({
|
|
28
|
+
useStaticInfo: () => ({ customer: { customerId, country, segment } }),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
jest.mock("react-router-native", () => ({
|
|
32
|
+
...jest.requireActual("react-router-native"),
|
|
33
|
+
useLocation: () => jest.fn(),
|
|
34
|
+
useNavigate: () => jest.fn(),
|
|
35
|
+
useMatch: () => false,
|
|
36
|
+
useParams: () => ({ id: mockFirstCheckoutItemId }),
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
jest.mock("../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId");
|
|
40
|
+
jest.mock("../../../projection/returnQuestion/react/useListReturnQuestionsByCheckoutItemId");
|
|
41
|
+
jest.mock("../../../domain/checkoutItem/react/useReturnCheckoutItem");
|
|
42
|
+
|
|
43
|
+
describe("Return", () => {
|
|
44
|
+
test("renders correctly", async () => {
|
|
45
|
+
(useViewFirstAvailableCheckoutByCustomerId as jest.Mock).mockReturnValue([mockCheckout, QueryStatus.SUCCESS]);
|
|
46
|
+
(useListReturnQuestionsByCheckoutItemId as jest.Mock).mockReturnValue([mockReturnQuestions, QueryStatus.SUCCESS]);
|
|
47
|
+
const mockReturnCheckoutItem = jest.fn();
|
|
48
|
+
(useReturnCheckoutItem as jest.Mock).mockReturnValue([mockReturnCheckoutItem, CommandStatus.IDLE]);
|
|
49
|
+
|
|
50
|
+
const { findByTestId } = render(<Return layout={DummyLayout} />);
|
|
51
|
+
|
|
52
|
+
expect(await findByTestId("return-questions-form")).toBeTruthy();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -1,216 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { Box, Button, Layout, Spinner, Text, View, useDevice } from "@lookiero/aurora";
|
|
6
|
-
import { useI18nMessage } from "@lookiero/i18n-react";
|
|
7
|
-
import { CommandStatus, QueryStatus } from "@lookiero/messaging-react";
|
|
8
|
-
import { useLogger } from "@lookiero/sty-psp-logging";
|
|
9
|
-
import { Segment } from "@lookiero/sty-psp-segment";
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
import { useParams } from "react-router-native";
|
|
3
|
+
import { Spinner } from "@lookiero/aurora";
|
|
4
|
+
import { QueryStatus } from "@lookiero/messaging-react";
|
|
10
5
|
import { Layout as UiLayout } from "@lookiero/sty-psp-ui";
|
|
11
|
-
import { CheckoutProjection } from "../../../../projection/checkout/checkout";
|
|
12
6
|
import { CheckoutItemProjection } from "../../../../projection/checkoutItem/checkoutItem";
|
|
13
|
-
import { FeedbackProjection } from "../../../../projection/feedback/feedback";
|
|
14
|
-
import { ReturnQuestionType } from "../../../../projection/returnQuestion/returnQuestion";
|
|
15
|
-
import { Country } from "../../../../projection/shared/country";
|
|
16
|
-
import { useReturnCheckoutItem } from "../../../domain/checkoutItem/react/useReturnCheckoutItem";
|
|
17
7
|
import { useViewFirstAvailableCheckoutByCustomerId } from "../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
18
|
-
import {
|
|
19
|
-
import { TrackingPage } from "../../../tracking/tracking";
|
|
20
|
-
import { useTrackPageView } from "../../../tracking/useTrackPageView";
|
|
21
|
-
import { useTrackPressNext } from "../../../tracking/useTrackPressNext";
|
|
22
|
-
import { useTrackPressPrevious } from "../../../tracking/useTrackPressPrevious";
|
|
23
|
-
import { useTrackReturnItem } from "../../../tracking/useTrackReturnItem";
|
|
24
|
-
import { ReturnQuestions } from "../../components/organisms/returnQuestions/ReturnQuestions";
|
|
25
|
-
import {
|
|
26
|
-
ReturnQuestionFeedbackProvider,
|
|
27
|
-
useReturnQuestionFeedback,
|
|
28
|
-
} from "../../components/organisms/returnQuestions/behaviors/useReturnQuestionFeedback";
|
|
29
|
-
import {
|
|
30
|
-
ReturnQuestionItemProvider,
|
|
31
|
-
ReturnQuestionItems,
|
|
32
|
-
} from "../../components/organisms/returnQuestions/behaviors/useReturnQuestionItem";
|
|
33
|
-
import { HostDefaultReturnQuestionItem } from "../../components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem";
|
|
34
|
-
import { HostRadioGroupReturnQuestionItem } from "../../components/organisms/returnQuestions/components/hostRadioGroupReturnQuestionItem/HostRadioGroupReturnQuestionItem";
|
|
35
|
-
import { HostStackReturnQuestionItem } from "../../components/organisms/returnQuestions/components/hostStackReturnQuestionItem/form/HostStackReturnQuestionItem";
|
|
36
|
-
import { RadioReturnQuestionItem } from "../../components/organisms/returnQuestions/components/radioReturnQuestionItem/RadioReturnQuestionItem";
|
|
37
|
-
import { TextareaReturnQuestionItem } from "../../components/organisms/returnQuestions/components/textareaReturnQuestionItem/TextareaReturnQuestionItem";
|
|
38
|
-
import { ItemHeader } from "../../components/templates/header/itemHeader/ItemHeader";
|
|
8
|
+
import { ReturnQuestionFeedbackProvider } from "../../components/organisms/returnQuestions/behaviors/useReturnQuestionFeedback";
|
|
39
9
|
import { useStaticInfo } from "../../hooks/useStaticInfo";
|
|
40
|
-
import {
|
|
41
|
-
import { Routes } from "../../routing/routes";
|
|
42
|
-
import { useBasePath } from "../../routing/useBasePath";
|
|
43
|
-
import { style } from "./Return.style";
|
|
44
|
-
import { ProductVariantPreview } from "./components/productVariantPreview/ProductVariantPreview";
|
|
45
|
-
|
|
46
|
-
const returnQuestionItems: ReturnQuestionItems = {
|
|
47
|
-
[ReturnQuestionType.HOST_DEFAULT]: HostDefaultReturnQuestionItem,
|
|
48
|
-
[ReturnQuestionType.HOST_TEXTAREA]: HostDefaultReturnQuestionItem,
|
|
49
|
-
[ReturnQuestionType.HOST_SELECT]: HostRadioGroupReturnQuestionItem,
|
|
50
|
-
[ReturnQuestionType.HOST_STACK]: HostStackReturnQuestionItem,
|
|
51
|
-
[ReturnQuestionType.TEXTAREA]: TextareaReturnQuestionItem,
|
|
52
|
-
[ReturnQuestionType.OPTION]: RadioReturnQuestionItem,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
interface ReturnFormProps {
|
|
56
|
-
readonly checkoutItem: CheckoutItemProjection;
|
|
57
|
-
readonly country: Country;
|
|
58
|
-
readonly segment: Segment;
|
|
59
|
-
readonly layout: UiLayout;
|
|
60
|
-
readonly checkout: CheckoutProjection;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const ReturnForm: FC<ReturnFormProps> = ({ checkout, checkoutItem, country, segment, layout: UiLayout }) => {
|
|
64
|
-
const { screen } = useDevice();
|
|
65
|
-
const navigate = useNavigate();
|
|
66
|
-
const logger = useLogger();
|
|
67
|
-
const basePath = useBasePath();
|
|
68
|
-
const checkoutId = checkout.id;
|
|
69
|
-
const trackPressNext = useTrackPressNext({
|
|
70
|
-
page: TrackingPage.ITEM,
|
|
71
|
-
country,
|
|
72
|
-
segment,
|
|
73
|
-
checkoutId,
|
|
74
|
-
});
|
|
75
|
-
const trackPressPrevious = useTrackPressPrevious({
|
|
76
|
-
page: TrackingPage.ITEM,
|
|
77
|
-
country,
|
|
78
|
-
segment,
|
|
79
|
-
checkoutId,
|
|
80
|
-
});
|
|
81
|
-
const titleText = useI18nMessage({ id: I18nMessages.RETURN_QUESTIONS_TITLE });
|
|
82
|
-
const descriptionText = useI18nMessage({ id: I18nMessages.RETURN_QUESTIONS_DESCRIPTION });
|
|
83
|
-
const submitButtonText = useI18nMessage({ id: I18nMessages.RETURN_QUESTIONS_SUBMIT_BUTTON });
|
|
84
|
-
const isSmallScreen = screen.S;
|
|
85
|
-
|
|
86
|
-
useTrackPageView({ checkoutId, country, segment, page: TrackingPage.RETURN });
|
|
87
|
-
|
|
88
|
-
/* ReturnCheckoutItem */
|
|
89
|
-
const [returnQuestions] = useListReturnQuestionsByCheckoutItemId({
|
|
90
|
-
checkoutItemId: checkoutItem.id,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const [returnCheckoutItem, returnCheckoutItemStatus] = useReturnCheckoutItem({
|
|
94
|
-
checkoutItemId: checkoutItem.id,
|
|
95
|
-
logger,
|
|
96
|
-
});
|
|
97
|
-
const trackReturnItem = useTrackReturnItem({
|
|
98
|
-
page: TrackingPage.RETURN,
|
|
99
|
-
country,
|
|
100
|
-
segment,
|
|
101
|
-
checkoutId: checkoutId,
|
|
102
|
-
checkoutItemId: checkoutItem.id,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const navigateToNextItem = useCallback(() => {
|
|
106
|
-
const item = checkoutItem;
|
|
107
|
-
const items = checkout?.items as CheckoutItemProjection[];
|
|
108
|
-
const itemIndex = items.indexOf(item);
|
|
109
|
-
const nextItemIndex = itemIndex === items.length - 1 ? 0 : itemIndex + 1;
|
|
110
|
-
const nextItem = items[nextItemIndex] as CheckoutItemProjection;
|
|
111
|
-
|
|
112
|
-
trackPressNext({ from: item.id, to: nextItem.id });
|
|
113
|
-
navigate(generatePath(`${basePath}/${Routes.ITEM}`, { id: nextItem.id }));
|
|
114
|
-
}, [basePath, checkout?.items, checkoutItem, navigate, trackPressNext]);
|
|
115
|
-
|
|
116
|
-
const navigateToPreviousItem = useCallback(() => {
|
|
117
|
-
const item = checkoutItem;
|
|
118
|
-
const items = checkout?.items as CheckoutItemProjection[];
|
|
119
|
-
const itemIndex = items.indexOf(item);
|
|
120
|
-
const previousItemIndex = itemIndex === 0 ? items.length - 1 : itemIndex - 1;
|
|
121
|
-
const previousItem = items[previousItemIndex] as CheckoutItemProjection;
|
|
122
|
-
|
|
123
|
-
trackPressPrevious({ from: item.id, to: previousItem.id });
|
|
124
|
-
|
|
125
|
-
navigate(generatePath(`${basePath}/${Routes.ITEM}`, { id: previousItem.id }));
|
|
126
|
-
}, [basePath, checkout?.items, checkoutItem, navigate, trackPressPrevious]);
|
|
127
|
-
|
|
128
|
-
const returnItem = useCallback(
|
|
129
|
-
async (feedbacks: FeedbackProjection) => {
|
|
130
|
-
returnCheckoutItem({ feedbacks });
|
|
131
|
-
trackReturnItem();
|
|
132
|
-
navigateToNextItem();
|
|
133
|
-
},
|
|
134
|
-
[navigateToNextItem, returnCheckoutItem, trackReturnItem],
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const feedback = useReturnQuestionFeedback();
|
|
138
|
-
|
|
139
|
-
const handleOnSubmit = useCallback(() => returnItem(feedback), [feedback, returnItem]);
|
|
140
|
-
|
|
141
|
-
const header = useMemo(
|
|
142
|
-
() => (
|
|
143
|
-
<Box style={style.headerWrapper}>
|
|
144
|
-
<ItemHeader
|
|
145
|
-
item={checkoutItem}
|
|
146
|
-
items={checkout?.items as CheckoutItemProjection[]}
|
|
147
|
-
onNext={navigateToNextItem}
|
|
148
|
-
onPrevious={navigateToPreviousItem}
|
|
149
|
-
/>
|
|
150
|
-
</Box>
|
|
151
|
-
),
|
|
152
|
-
[checkout?.items, checkoutItem, navigateToNextItem, navigateToPreviousItem],
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
/* ReturnCheckoutItem */
|
|
156
|
-
|
|
157
|
-
const dependenciesLoaded = checkoutItem && returnQuestions && returnCheckoutItemStatus !== CommandStatus.LOADING;
|
|
158
|
-
|
|
159
|
-
if (!dependenciesLoaded) {
|
|
160
|
-
return <Spinner />;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return (
|
|
164
|
-
<ReturnQuestionItemProvider returnQuestionItems={returnQuestionItems}>
|
|
165
|
-
<PortalHost name="return-question-form-portal" />
|
|
166
|
-
<UiLayout
|
|
167
|
-
header={header}
|
|
168
|
-
scrollEnabled={false}
|
|
169
|
-
style={{
|
|
170
|
-
safeAreaView: style.safeAreaView,
|
|
171
|
-
scrollView: style.scrollView,
|
|
172
|
-
}}
|
|
173
|
-
>
|
|
174
|
-
<ProductVariantPreview country={country} item={checkoutItem} />
|
|
175
|
-
|
|
176
|
-
<ScrollView showsVerticalScrollIndicator={false}>
|
|
177
|
-
<Layout fullWidth={!screen.L} style={[style.layout, screen.L ? style.desktopLayoutSpacing : undefined]}>
|
|
178
|
-
<Box size={{ L: "2/3" }}>
|
|
179
|
-
<View style={[style.info, isSmallScreen ? undefined : style.desktopInfo]}>
|
|
180
|
-
<Text level={3} heading>
|
|
181
|
-
{titleText}
|
|
182
|
-
</Text>
|
|
183
|
-
<Text level={1} style={style.description} detail>
|
|
184
|
-
{descriptionText}
|
|
185
|
-
</Text>
|
|
186
|
-
</View>
|
|
187
|
-
|
|
188
|
-
<ReturnQuestions portalHostName="return-question-form-portal" returnQuestions={returnQuestions} />
|
|
189
|
-
|
|
190
|
-
<View style={style.submit}>
|
|
191
|
-
<Button testID="return-questions-button" onPress={handleOnSubmit}>
|
|
192
|
-
{submitButtonText}
|
|
193
|
-
</Button>
|
|
194
|
-
</View>
|
|
195
|
-
</Box>
|
|
196
|
-
</Layout>
|
|
197
|
-
</ScrollView>
|
|
198
|
-
</UiLayout>
|
|
199
|
-
</ReturnQuestionItemProvider>
|
|
200
|
-
);
|
|
201
|
-
};
|
|
10
|
+
import { ReturnQuestionsForm } from "./components/returnQuestionsForm/ReturnQuestionsForm";
|
|
202
11
|
|
|
203
12
|
interface ReturnProps {
|
|
204
13
|
readonly layout: UiLayout;
|
|
205
14
|
}
|
|
206
15
|
|
|
207
|
-
const Return: FC<ReturnProps> = ({ layout
|
|
16
|
+
const Return: FC<ReturnProps> = ({ layout }) => {
|
|
208
17
|
const { id } = useParams();
|
|
209
18
|
const {
|
|
210
19
|
customer: { customerId, country, segment },
|
|
211
20
|
} = useStaticInfo();
|
|
21
|
+
|
|
212
22
|
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
23
|
+
|
|
213
24
|
const checkoutItem = checkout?.items.find((checkoutItem) => checkoutItem.id === id) as CheckoutItemProjection;
|
|
25
|
+
|
|
214
26
|
const dependenciesLoaded = checkoutStatus !== QueryStatus.LOADING && checkout && checkoutItem;
|
|
215
27
|
|
|
216
28
|
if (!dependenciesLoaded) {
|
|
@@ -219,11 +31,11 @@ const Return: FC<ReturnProps> = ({ layout: UiLayout }) => {
|
|
|
219
31
|
|
|
220
32
|
return (
|
|
221
33
|
<ReturnQuestionFeedbackProvider key={checkoutItem.id} feedback={checkoutItem.feedbacks || {}}>
|
|
222
|
-
<
|
|
34
|
+
<ReturnQuestionsForm
|
|
223
35
|
checkout={checkout}
|
|
224
36
|
checkoutItem={checkoutItem}
|
|
225
37
|
country={country}
|
|
226
|
-
layout={
|
|
38
|
+
layout={layout}
|
|
227
39
|
segment={segment}
|
|
228
40
|
/>
|
|
229
41
|
</ReturnQuestionFeedbackProvider>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Country } from "@lookiero/sty-psp-locale";
|
|
3
|
+
import { CheckoutItemStatus } from "../../../../../../domain/checkoutItem/model/checkoutItem";
|
|
4
|
+
import { checkoutItem } from "../../../../../projection/checkoutItem/checkoutItem.mock";
|
|
5
|
+
import { I18nMessages } from "../../../../i18n/i18n";
|
|
6
|
+
import { render } from "../../../../test/render";
|
|
7
|
+
import { ProductVariantPreview } from "./ProductVariantPreview";
|
|
8
|
+
|
|
9
|
+
const country = Country.ES;
|
|
10
|
+
const checkoutItemProjection = checkoutItem({ status: CheckoutItemStatus.RETURNED });
|
|
11
|
+
|
|
12
|
+
describe("ProductVariantPreview", () => {
|
|
13
|
+
it("matches the snapshot", async () => {
|
|
14
|
+
const { toJSON } = render(<ProductVariantPreview country={country} item={checkoutItemProjection} />);
|
|
15
|
+
|
|
16
|
+
expect(toJSON()).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("renders correctly", async () => {
|
|
20
|
+
const { getByTestId, getByText } = render(
|
|
21
|
+
<ProductVariantPreview country={country} item={checkoutItemProjection} />,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(getByTestId("product-variant-preview")).toBeTruthy();
|
|
25
|
+
expect(getByTestId("product-variant-image")).toBeTruthy();
|
|
26
|
+
expect(getByTestId("price")).toBeTruthy();
|
|
27
|
+
|
|
28
|
+
expect(getByText(checkoutItemProjection.productVariant.brand)).toBeTruthy();
|
|
29
|
+
expect(getByText(checkoutItemProjection.productVariant.name)).toBeTruthy();
|
|
30
|
+
expect(getByText(`${I18nMessages.ITEM_SIZE} ${checkoutItemProjection.productVariant.size.lookiero}`)).toBeTruthy();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -19,19 +19,22 @@ interface ProductVariantPreviewProps {
|
|
|
19
19
|
const ProductVariantPreview: FC<ProductVariantPreviewProps> = ({ item, country }) => {
|
|
20
20
|
const cdnImageUrl = useMediaImage();
|
|
21
21
|
const { screen } = useDevice();
|
|
22
|
-
const isSmallScreen = screen.S;
|
|
23
|
-
const { productVariant, price } = item;
|
|
24
|
-
const { media, brand, name, size: sizeProjection } = productVariant;
|
|
25
|
-
const mainImage = media.find((mediaElement) => mediaElement.perspective === "MAIN");
|
|
26
22
|
|
|
27
23
|
const sizeText = useI18nMessage({ id: I18nMessages.ITEM_SIZE });
|
|
28
24
|
const uniqueText = useI18nMessage({ id: I18nMessages.ITEM_UNIQUE });
|
|
29
25
|
|
|
26
|
+
const {
|
|
27
|
+
productVariant: { media, brand, name, size: sizeProjection },
|
|
28
|
+
price,
|
|
29
|
+
} = item;
|
|
30
|
+
|
|
31
|
+
const mainImage = media.find((mediaElement) => mediaElement.perspective === "MAIN");
|
|
32
|
+
|
|
30
33
|
return (
|
|
31
|
-
<View style={[style.wrapper,
|
|
34
|
+
<View style={[style.wrapper, !screen.S && style.mobileWrapper]} testID="product-variant-preview">
|
|
32
35
|
<Row style={style.row}>
|
|
33
36
|
<Column size={{ M: "2/3", L: "2/3" }} style={style.content}>
|
|
34
|
-
{mainImage
|
|
37
|
+
{mainImage && (
|
|
35
38
|
<Image
|
|
36
39
|
resizeMode="stretch"
|
|
37
40
|
style={style.image}
|
|
@@ -43,7 +46,8 @@ const ProductVariantPreview: FC<ProductVariantPreviewProps> = ({ item, country }
|
|
|
43
46
|
}),
|
|
44
47
|
}}
|
|
45
48
|
/>
|
|
46
|
-
)
|
|
49
|
+
)}
|
|
50
|
+
|
|
47
51
|
<View style={style.info}>
|
|
48
52
|
<Text color={COLOR.TEXT_MEDIUM} level={2} detail>
|
|
49
53
|
{brand}
|
|
@@ -55,6 +59,7 @@ const ProductVariantPreview: FC<ProductVariantPreviewProps> = ({ item, country }
|
|
|
55
59
|
{`${sizeText} ${sizeProjection.unique ? uniqueText : size({ size: sizeProjection, country })}`}
|
|
56
60
|
</Text>
|
|
57
61
|
</View>
|
|
62
|
+
|
|
58
63
|
<View style={style.price}>
|
|
59
64
|
<Price price={price} withPercentage />
|
|
60
65
|
</View>
|