@lookiero/checkout 8.18.0 → 8.19.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.
Files changed (78) hide show
  1. package/cypress/support/interceptListReturnQuestionsByCheckoutItemId.ts +1 -1
  2. package/dist/src/infrastructure/projection/returnQuestion/httpReturnQuestionsByCheckoutItemIdView.js +1 -1
  3. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/ReturnQuestion.js +3 -1
  4. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/behaviors/isChildReturnQuestion.js +2 -1
  5. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/behaviors/useReturnQuestionItem.d.ts +3 -3
  6. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/ReturnQuestionItem.d.ts +4 -3
  7. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionFeedbackItem/HostDefaultReturnQuestionFeedbackItem.d.ts +2 -1
  8. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionFeedbackItem/HostDefaultReturnQuestionFeedbackItem.js +1 -0
  9. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.d.ts +2 -1
  10. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.js +8 -6
  11. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostRadioGroupReturnQuestionItem/HostRadioGroupReturnQuestionItem.d.ts +2 -1
  12. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostRadioGroupReturnQuestionItem/HostRadioGroupReturnQuestionItem.js +2 -1
  13. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostSelectReturnQuestionItem/HostSelectReturnQuestionItem.d.ts +2 -1
  14. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostSelectReturnQuestionItem/HostSelectReturnQuestionItem.js +2 -1
  15. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostStackReturnQuestionItem/form/HostStackReturnQuestionItem.d.ts +2 -1
  16. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostStackReturnQuestionItem/form/HostStackReturnQuestionItem.js +1 -0
  17. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostStackReturnQuestionItem/modal/HostStackReturnQuestionItem.d.ts +2 -1
  18. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/hostStackReturnQuestionItem/modal/HostStackReturnQuestionItem.js +5 -3
  19. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/modalOptionReturnQuestionItems/ModalOptionReturnQuestionItems.js +4 -2
  20. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/optionReturnQuestionItem/OptionReturnQuestionItem.d.ts +2 -1
  21. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/optionReturnQuestionItem/OptionReturnQuestionItem.js +2 -1
  22. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/radioReturnQuestionItem/RadioReturnQuestionItem.d.ts +2 -1
  23. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/radioReturnQuestionItem/RadioReturnQuestionItem.js +2 -1
  24. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/returnQuestionFeedbackItem/ReturnQuestionFeedbackItem.d.ts +2 -1
  25. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/returnQuestionFeedbackItem/ReturnQuestionFeedbackItem.js +2 -1
  26. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/textareaReturnQuestionItem/TextareaReturnQuestionItem.d.ts +2 -1
  27. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/components/textareaReturnQuestionItem/TextareaReturnQuestionItem.js +2 -1
  28. package/dist/src/infrastructure/ui/components/organisms/returnQuestions/util/returnQuestionFeedback.js +18 -9
  29. package/dist/src/infrastructure/ui/views/item/components/returnQuestionsFeedback/ReturnQuestionsFeedback.js +1 -1
  30. package/dist/src/infrastructure/ui/views/return/components/returnQuestionsForm/ReturnQuestionsForm.js +1 -1
  31. package/dist/src/projection/returnQuestion/returnQuestion.constants.d.ts +9 -0
  32. package/dist/src/projection/returnQuestion/returnQuestion.constants.js +10 -0
  33. package/dist/src/projection/returnQuestion/returnQuestion.d.ts +23 -16
  34. package/dist/src/projection/returnQuestion/returnQuestion.js +1 -11
  35. package/dist/src/projection/returnQuestion/returnQuestion.metadata.d.ts +12 -0
  36. package/dist/src/projection/returnQuestion/returnQuestion.metadata.js +1 -0
  37. package/dist/src/projection/returnQuestion/returnQuestion.typeguard.d.ts +5 -0
  38. package/dist/src/projection/returnQuestion/returnQuestion.typeguard.js +10 -0
  39. package/dist/src/version.d.ts +1 -1
  40. package/dist/src/version.js +1 -1
  41. package/package.json +1 -1
  42. package/src/infrastructure/projection/returnQuestion/httpReturnQuestionsByCheckoutItemIdView.ts +1 -1
  43. package/src/infrastructure/projection/returnQuestion/react/useListReturnQuestionsByCheckoutItemId.test.ts +4 -9
  44. package/src/infrastructure/projection/returnQuestion/returnQuestions.mock.ts +72 -117
  45. package/src/infrastructure/ui/components/organisms/returnQuestions/ReturnQuestion.test.tsx +10 -12
  46. package/src/infrastructure/ui/components/organisms/returnQuestions/ReturnQuestion.tsx +10 -8
  47. package/src/infrastructure/ui/components/organisms/returnQuestions/ReturnQuestions.test.tsx +10 -9
  48. package/src/infrastructure/ui/components/organisms/returnQuestions/behaviors/isChildReturnQuestion.ts +2 -1
  49. package/src/infrastructure/ui/components/organisms/returnQuestions/behaviors/useReturnQuestionItem.test.tsx +7 -9
  50. package/src/infrastructure/ui/components/organisms/returnQuestions/behaviors/useReturnQuestionItem.tsx +3 -3
  51. package/src/infrastructure/ui/components/organisms/returnQuestions/components/ReturnQuestionItem.ts +4 -3
  52. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionFeedbackItem/HostDefaultReturnQuestionFeedbackItem.test.tsx +7 -13
  53. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionFeedbackItem/HostDefaultReturnQuestionFeedbackItem.tsx +4 -2
  54. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.test.tsx +8 -14
  55. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem.tsx +13 -7
  56. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostRadioGroupReturnQuestionItem/HostRadioGroupReturnQuestionItem.tsx +7 -5
  57. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostSelectReturnQuestionItem/HostSelectReturnQuestionItem.test.tsx +10 -14
  58. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostSelectReturnQuestionItem/HostSelectReturnQuestionItem.tsx +7 -5
  59. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostStackReturnQuestionItem/form/HostStackReturnQuestionItem.tsx +5 -3
  60. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostStackReturnQuestionItem/modal/HostStackReturnQuestionItem.test.tsx +43 -36
  61. package/src/infrastructure/ui/components/organisms/returnQuestions/components/hostStackReturnQuestionItem/modal/HostStackReturnQuestionItem.tsx +10 -7
  62. package/src/infrastructure/ui/components/organisms/returnQuestions/components/modalOptionReturnQuestionItems/ModalOptionReturnQuestionItems.tsx +11 -9
  63. package/src/infrastructure/ui/components/organisms/returnQuestions/components/optionReturnQuestionItem/OptionReturnQuestionItem.test.tsx +8 -14
  64. package/src/infrastructure/ui/components/organisms/returnQuestions/components/optionReturnQuestionItem/OptionReturnQuestionItem.tsx +6 -4
  65. package/src/infrastructure/ui/components/organisms/returnQuestions/components/radioReturnQuestionItem/RadioReturnQuestionItem.tsx +6 -4
  66. package/src/infrastructure/ui/components/organisms/returnQuestions/components/returnQuestionFeedbackItem/ReturnQuestionFeedbackItem.test.tsx +23 -25
  67. package/src/infrastructure/ui/components/organisms/returnQuestions/components/returnQuestionFeedbackItem/ReturnQuestionFeedbackItem.tsx +5 -3
  68. package/src/infrastructure/ui/components/organisms/returnQuestions/components/textareaReturnQuestionItem/TextareaReturnQuestionItem.test.tsx +9 -29
  69. package/src/infrastructure/ui/components/organisms/returnQuestions/components/textareaReturnQuestionItem/TextareaReturnQuestionItem.tsx +7 -5
  70. package/src/infrastructure/ui/components/organisms/returnQuestions/util/__snapshots__/returnQuestionFeedback.test.ts.snap +5 -4
  71. package/src/infrastructure/ui/components/organisms/returnQuestions/util/returnQuestionFeedback.ts +32 -18
  72. package/src/infrastructure/ui/views/item/components/returnQuestionsFeedback/ReturnQuestionsFeedback.tsx +2 -4
  73. package/src/infrastructure/ui/views/return/components/returnQuestionsForm/ReturnQuestionsForm.tsx +1 -1
  74. package/src/projection/returnQuestion/listReturnQuestionsByCheckoutItemId.test.ts +4 -12
  75. package/src/projection/returnQuestion/returnQuestion.constants.ts +10 -0
  76. package/src/projection/returnQuestion/returnQuestion.metadata.ts +17 -0
  77. package/src/projection/returnQuestion/returnQuestion.ts +42 -20
  78. package/src/projection/returnQuestion/returnQuestion.typeguard.ts +24 -0
@@ -1,8 +1,6 @@
1
1
  import React from "react";
2
- import {
3
- ReturnQuestionProjection,
4
- ReturnQuestionType,
5
- } from "../../../../../../../projection/returnQuestion/returnQuestion";
2
+ import { ReturnQuestionProjection } from "../../../../../../../projection/returnQuestion/returnQuestion";
3
+ import { ReturnQuestionType } from "../../../../../../../projection/returnQuestion/returnQuestion.constants";
6
4
  import { feedback as mockFeedback } from "../../../../../../projection/feedback/feedback.mock";
7
5
  import { I18nMessages } from "../../../../../i18n/i18n";
8
6
  import { render } from "../../../../../test/render";
@@ -12,40 +10,34 @@ jest.mock("../../behaviors/useReturnQuestionFeedback", () => ({
12
10
  useReturnQuestionFeedback: () => mockFeedback,
13
11
  }));
14
12
 
15
- const returnQuestion: ReturnQuestionProjection = {
13
+ const returnQuestion: ReturnQuestionProjection<ReturnQuestionType.HOST_DEFAULT> = {
16
14
  id: "0ad1dba8-b02c-4121-a1e3-981f1c30800d",
17
- name: "size_title",
18
- placeholder: "",
19
- type: ReturnQuestionType.HOST_STACK,
15
+ translationKey: "size_title",
16
+ type: ReturnQuestionType.HOST_DEFAULT,
20
17
  children: [
21
18
  {
22
19
  id: "9251dc2c-d76a-484d-9299-346929af932f",
23
- name: "size_large",
24
- placeholder: "",
20
+ translationKey: "size_large",
25
21
  type: ReturnQuestionType.OPTION,
26
22
  children: [
27
23
  {
28
24
  id: "542c4d24-e1da-484f-8c3a-7d89ee135adc",
29
- name: "",
30
- placeholder: "",
31
- type: ReturnQuestionType.HOST_STACK,
25
+ translationKey: "",
26
+ type: ReturnQuestionType.HOST_DEFAULT,
32
27
  children: [
33
28
  {
34
29
  id: "68c0bb98-b00a-4b86-af43-528fe903cb69",
35
- name: "size_overall",
36
- placeholder: "",
30
+ translationKey: "size_overall",
37
31
  type: ReturnQuestionType.OPTION,
38
32
  },
39
33
  {
40
34
  id: "85e84a77-461c-41e6-8544-95b5294d0b80",
41
- name: "size_trousers_too_long",
42
- placeholder: "",
35
+ translationKey: "size_trousers_too_long",
43
36
  type: ReturnQuestionType.OPTION,
44
37
  },
45
38
  {
46
39
  id: "29441d25-8d9f-471e-a13e-a03f61c88091",
47
- name: "size_fit_cut_does_not_fit",
48
- placeholder: "",
40
+ translationKey: "size_fit_cut_does_not_fit",
49
41
  type: ReturnQuestionType.OPTION,
50
42
  },
51
43
  ],
@@ -54,11 +46,17 @@ const returnQuestion: ReturnQuestionProjection = {
54
46
  },
55
47
  ],
56
48
  };
57
- const returnQuestionUnanswered: ReturnQuestionProjection = {
49
+ const returnQuestionUnanswered: ReturnQuestionProjection<ReturnQuestionType.HOST_DEFAULT> = {
58
50
  id: "fd7ff4a0-78ed-4c0d-aa4d-64962739c322",
59
- name: "style_title",
60
- placeholder: "",
61
- type: ReturnQuestionType.HOST_STACK,
51
+ translationKey: "style_title",
52
+ type: ReturnQuestionType.HOST_DEFAULT,
53
+ children: [
54
+ {
55
+ id: "68c0bb98-b00a-4b86-af43-528fe903cb69",
56
+ translationKey: "size_overall",
57
+ type: ReturnQuestionType.OPTION,
58
+ },
59
+ ],
62
60
  };
63
61
 
64
62
  describe("ReturnQuestionFeedbackItem component (ReturnQuestions organism)", () => {
@@ -70,7 +68,7 @@ describe("ReturnQuestionFeedbackItem component (ReturnQuestions organism)", () =
70
68
  />,
71
69
  );
72
70
 
73
- expect(getByText(returnQuestion.name)).toBeTruthy();
71
+ expect(getByText(returnQuestion.translationKey)).toBeTruthy();
74
72
  expect(getByText("size_large / size_overall")).toBeTruthy();
75
73
  });
76
74
 
@@ -82,7 +80,7 @@ describe("ReturnQuestionFeedbackItem component (ReturnQuestions organism)", () =
82
80
  />,
83
81
  );
84
82
 
85
- expect(getByText(returnQuestionUnanswered.name)).toBeTruthy();
83
+ expect(getByText(returnQuestionUnanswered.translationKey)).toBeTruthy();
86
84
  expect(getByText(I18nMessages.FEEDBACK_UNANSWERED)).toBeTruthy();
87
85
  });
88
86
  });
@@ -1,15 +1,17 @@
1
+ /* eslint-disable react/prop-types */
1
2
  import React, { useCallback } from "react";
2
3
  import { View } from "react-native";
3
4
  import { Text } from "@lookiero/aurora";
4
5
  import { useI18nMessage, useIntl } from "@lookiero/i18n-react";
6
+ import { ReturnQuestionType } from "../../../../../../../projection/returnQuestion/returnQuestion.constants";
5
7
  import { I18nMessages } from "../../../../../i18n/i18n";
6
8
  import { useReturnQuestionFeedback } from "../../behaviors/useReturnQuestionFeedback";
7
9
  import { feedbackForReturnQuestion } from "../../util/returnQuestionFeedback";
8
- import { ReturnQuestionItem, ReturnQuestionItemProps } from "../ReturnQuestionItem";
10
+ import { ReturnQuestionItem } from "../ReturnQuestionItem";
9
11
  import { style } from "./ReturnQuestionFeedbackItem.style";
10
12
 
11
- const ReturnQuestionFeedbackItem: ReturnQuestionItem = ({ returnQuestion }: ReturnQuestionItemProps) => {
12
- const titleText = useI18nMessage({ id: returnQuestion.name });
13
+ const ReturnQuestionFeedbackItem: ReturnQuestionItem<ReturnQuestionType.HOST_DEFAULT> = ({ returnQuestion }) => {
14
+ const titleText = useI18nMessage({ id: returnQuestion.translationKey });
13
15
  const unansweredText = useI18nMessage({ id: I18nMessages.FEEDBACK_UNANSWERED });
14
16
 
15
17
  const returnQuestionFeedback = useReturnQuestionFeedback();
@@ -1,9 +1,7 @@
1
1
  import { fireEvent } from "@testing-library/react-native";
2
2
  import React from "react";
3
- import {
4
- ReturnQuestionProjection,
5
- ReturnQuestionType,
6
- } from "../../../../../../../projection/returnQuestion/returnQuestion";
3
+ import { ReturnQuestionProjection } from "../../../../../../../projection/returnQuestion/returnQuestion";
4
+ import { ReturnQuestionType } from "../../../../../../../projection/returnQuestion/returnQuestion.constants";
7
5
  import { render } from "../../../../../test/render";
8
6
  import { TextareaReturnQuestionItem } from "./TextareaReturnQuestionItem";
9
7
 
@@ -15,31 +13,13 @@ jest.mock("../../behaviors/useReturnQuestionFeedback", () => ({
15
13
  const returnQuestionParent = {
16
14
  id: "0ad1dba8-b02c-4121-a1e3-981f1c30800d",
17
15
  } as ReturnQuestionProjection;
18
- const returnQuestion: ReturnQuestionProjection = {
19
- id: "9251dc2c-d76a-484d-9299-346929af932f",
20
- name: "size_large",
21
- placeholder: "",
22
- type: ReturnQuestionType.OPTION,
23
- children: [
24
- {
25
- id: "68c0bb98-b00a-4b86-af43-528fe903cb69",
26
- name: "size_overall",
27
- placeholder: "",
28
- type: ReturnQuestionType.OPTION,
29
- },
30
- {
31
- id: "85e84a77-461c-41e6-8544-95b5294d0b80",
32
- name: "size_trousers_too_long",
33
- placeholder: "",
34
- type: ReturnQuestionType.OPTION,
35
- },
36
- {
37
- id: "29441d25-8d9f-471e-a13e-a03f61c88091",
38
- name: "size_fit_cut_does_not_fit",
39
- placeholder: "",
40
- type: ReturnQuestionType.OPTION,
41
- },
42
- ],
16
+ const returnQuestion: ReturnQuestionProjection<ReturnQuestionType.TEXTAREA> = {
17
+ id: "1123a37d-bc00-43a4-9d28-cee1dfaf356c",
18
+ translationKey: "comment_textarea",
19
+ type: ReturnQuestionType.TEXTAREA,
20
+ metadata: {
21
+ placeholder: "comment_textarea_placeholder",
22
+ },
43
23
  };
44
24
 
45
25
  describe("TextareaReturnQuestionItem component (ReturnQuestions organism)", () => {
@@ -1,21 +1,23 @@
1
+ /* eslint-disable react/prop-types */
1
2
  import React, { useCallback, useMemo } from "react";
2
3
  import { View } from "@lookiero/aurora";
3
4
  import { useIntl } from "@lookiero/i18n-react";
5
+ import { ReturnQuestionType } from "../../../../../../../projection/returnQuestion/returnQuestion.constants";
4
6
  import { InputField } from "../../../../../../../shared/ui/components/molecules/inputField/InputField";
5
7
  import { useReturnQuestionFeedbackForReturnQuestion } from "../../behaviors/useReturnQuestionFeedback";
6
- import { ReturnQuestionItem, ReturnQuestionItemProps } from "../ReturnQuestionItem";
8
+ import { ReturnQuestionItem } from "../ReturnQuestionItem";
7
9
  import { style } from "./TextareaReturnQuestionItem.style";
8
10
 
9
- const TextareaReturnQuestionItem: ReturnQuestionItem = ({
11
+ const TextareaReturnQuestionItem: ReturnQuestionItem<ReturnQuestionType.TEXTAREA> = ({
10
12
  returnQuestion,
11
13
  returnQuestionParent,
12
14
  testID,
13
- }: ReturnQuestionItemProps) => {
15
+ }) => {
14
16
  const { formatMessage } = useIntl();
15
17
 
16
18
  const placeholderText = useMemo(
17
- () => (returnQuestion.placeholder ? formatMessage({ id: returnQuestion.placeholder }) : ""),
18
- [formatMessage, returnQuestion.placeholder],
19
+ () => (returnQuestion.metadata.placeholder ? formatMessage({ id: returnQuestion.metadata.placeholder }) : ""),
20
+ [formatMessage, returnQuestion.metadata.placeholder],
19
21
  );
20
22
 
21
23
  const { feedback, onChange } = useReturnQuestionFeedbackForReturnQuestion({ returnQuestion: returnQuestionParent });
@@ -13,14 +13,15 @@ exports[`returnQuestionFeedback utils return the deepest returnQuestion with fee
13
13
  "children": [
14
14
  {
15
15
  "id": "1123a37d-bc00-43a4-9d28-cee1dfaf356c",
16
- "name": "comment_textarea",
17
- "placeholder": "comment_textarea_placeholder",
16
+ "metadata": {
17
+ "placeholder": "comment_textarea_placeholder",
18
+ },
19
+ "translationKey": "comment_textarea",
18
20
  "type": "TEXTAREA",
19
21
  },
20
22
  ],
21
23
  "id": "ce3e8d57-5eea-4dd3-bef4-2e811a143612",
22
- "name": "comment_title",
23
- "placeholder": "",
24
+ "translationKey": "comment_title",
24
25
  "type": "HOST_TEXTAREA",
25
26
  },
26
27
  false,
@@ -1,6 +1,10 @@
1
1
  import { isUuid } from "@lookiero/sty-psp-uuid";
2
2
  import { FeedbackProjection } from "../../../../../../projection/feedback/feedback";
3
3
  import { ReturnQuestionProjection } from "../../../../../../projection/returnQuestion/returnQuestion";
4
+ import {
5
+ returnQuestionHasChildren,
6
+ returnQuestionWithTranslationKey,
7
+ } from "../../../../../../projection/returnQuestion/returnQuestion.typeguard";
4
8
 
5
9
  interface RecursiveFeedbackForReturnQuestionFunctionArgs {
6
10
  readonly feedback: FeedbackProjection;
@@ -25,14 +29,16 @@ const feedbackForReturnQuestion: RecursiveFeedbackForReturnQuestionFunction = ({
25
29
  const returnQuestionFeedback = feedback[returnQuestionId];
26
30
 
27
31
  if (isUuid(returnQuestionFeedback as string)) {
28
- const feebackReturnQuestionChild = returnQuestion.children?.find(
29
- (childReturnQuestion) => childReturnQuestion.id === returnQuestionFeedback,
30
- );
32
+ const feebackReturnQuestionChild =
33
+ returnQuestionHasChildren(returnQuestion) &&
34
+ returnQuestion.children?.find((childReturnQuestion) => childReturnQuestion.id === returnQuestionFeedback);
31
35
 
32
36
  if (feebackReturnQuestionChild) {
33
37
  return [
34
38
  ...acc,
35
- translate(feebackReturnQuestionChild?.name),
39
+ ...(returnQuestionWithTranslationKey(feebackReturnQuestionChild)
40
+ ? [translate(feebackReturnQuestionChild.translationKey)]
41
+ : []),
36
42
  ...feedbackForReturnQuestion({ feedback, returnQuestion: feebackReturnQuestionChild, translate, acc }),
37
43
  ];
38
44
  }
@@ -44,13 +50,15 @@ const feedbackForReturnQuestion: RecursiveFeedbackForReturnQuestionFunction = ({
44
50
  }
45
51
 
46
52
  return (
47
- returnQuestion.children?.reduce(
48
- (acc, childReturnQuestion) => [
49
- ...acc,
50
- ...feedbackForReturnQuestion({ feedback, returnQuestion: childReturnQuestion, translate, acc }),
51
- ],
52
- [] as string[],
53
- ) || []
53
+ (returnQuestionHasChildren(returnQuestion) &&
54
+ returnQuestion.children?.reduce(
55
+ (acc, childReturnQuestion) => [
56
+ ...acc,
57
+ ...feedbackForReturnQuestion({ feedback, returnQuestion: childReturnQuestion, translate, acc }),
58
+ ],
59
+ [] as string[],
60
+ )) ||
61
+ []
54
62
  );
55
63
  };
56
64
 
@@ -77,9 +85,9 @@ const deepestReturnQuestionWithFeedbackForReturnQuestion: RecursiveDeepestReturn
77
85
  const returnQuestionFeedback = feedback[returnQuestionId];
78
86
 
79
87
  if (isUuid(returnQuestionFeedback as string)) {
80
- const feebackReturnQuestionChild = returnQuestion.children?.find(
81
- (childReturnQuestion) => childReturnQuestion.id === returnQuestionFeedback,
82
- );
88
+ const feebackReturnQuestionChild =
89
+ returnQuestionHasChildren(returnQuestion) &&
90
+ returnQuestion.children?.find((childReturnQuestion) => childReturnQuestion.id === returnQuestionFeedback);
83
91
 
84
92
  if (feebackReturnQuestionChild) {
85
93
  return deepestReturnQuestionWithFeedbackForReturnQuestion({
@@ -95,9 +103,11 @@ const deepestReturnQuestionWithFeedbackForReturnQuestion: RecursiveDeepestReturn
95
103
  return [returnQuestion, false];
96
104
  }
97
105
 
98
- const feebackReturnQuestionChild = returnQuestion.children?.find((childReturnQuestion) =>
99
- Object.keys(feedback).find((id) => id === childReturnQuestion.id),
100
- );
106
+ const feebackReturnQuestionChild =
107
+ returnQuestionHasChildren(returnQuestion) &&
108
+ returnQuestion.children?.find((childReturnQuestion) =>
109
+ Object.keys(feedback).find((id) => id === childReturnQuestion.id),
110
+ );
101
111
 
102
112
  if (feebackReturnQuestionChild) {
103
113
  return deepestReturnQuestionWithFeedbackForReturnQuestion({
@@ -107,7 +117,11 @@ const deepestReturnQuestionWithFeedbackForReturnQuestion: RecursiveDeepestReturn
107
117
  });
108
118
  }
109
119
 
110
- return [deepestReturnQuestion, !returnQuestion.children || returnQuestion.children.length === 0];
120
+ const hasChildren = Boolean(
121
+ returnQuestionHasChildren(returnQuestion) && returnQuestion.children && returnQuestion.children.length > 0,
122
+ );
123
+
124
+ return [deepestReturnQuestion, !hasChildren];
111
125
  };
112
126
 
113
127
  export { feedbackForReturnQuestion, deepestReturnQuestionWithFeedbackForReturnQuestion };
@@ -2,10 +2,8 @@ import React, { FC } from "react";
2
2
  import { View } from "react-native";
3
3
  import { ButtonIcon, Text } from "@lookiero/aurora";
4
4
  import { useI18nMessage } from "@lookiero/i18n-react";
5
- import {
6
- ReturnQuestionProjection,
7
- ReturnQuestionType,
8
- } from "../../../../../../projection/returnQuestion/returnQuestion";
5
+ import { ReturnQuestionProjection } from "../../../../../../projection/returnQuestion/returnQuestion";
6
+ import { ReturnQuestionType } from "../../../../../../projection/returnQuestion/returnQuestion.constants";
9
7
  import { ReturnQuestions } from "../../../../components/organisms/returnQuestions/ReturnQuestions";
10
8
  import {
11
9
  ReturnQuestionItemProvider,
@@ -12,7 +12,7 @@ import { Segment } from "@lookiero/sty-psp-segment";
12
12
  import { Layout as UiLayout } from "@lookiero/sty-psp-ui";
13
13
  import { CheckoutProjection } from "../../../../../../projection/checkout/checkout";
14
14
  import { CheckoutItemProjection } from "../../../../../../projection/checkoutItem/checkoutItem";
15
- import { ReturnQuestionType } from "../../../../../../projection/returnQuestion/returnQuestion";
15
+ import { ReturnQuestionType } from "../../../../../../projection/returnQuestion/returnQuestion.constants";
16
16
  import { useReturnCheckoutItem } from "../../../../../domain/checkoutItem/react/useReturnCheckoutItem";
17
17
  import { useListReturnQuestionsByCheckoutItemId } from "../../../../../projection/returnQuestion/react/useListReturnQuestionsByCheckoutItemId";
18
18
  import { TrackingPage } from "../../../../../tracking/tracking";
@@ -1,30 +1,22 @@
1
1
  import { mock } from "jest-mock-extended";
2
2
  import { QueryBus } from "@lookiero/messaging";
3
+ import { returnQuestions } from "../../infrastructure/projection/returnQuestion/returnQuestions.mock";
3
4
  import {
4
5
  listReturnQuestionsByCheckoutItemId,
5
6
  listReturnQuestionsByCheckoutItemIdHandler as sut,
6
7
  } from "./listReturnQuestionsByCheckoutItemId";
7
- import { ReturnQuestionProjection, ReturnQuestionType } from "./returnQuestion";
8
8
 
9
9
  const checkoutItemId = "29790d24-b139-4ab8-b618-d796d101e974";
10
- const returnQuestionsProjection: ReturnQuestionProjection[] = [
11
- {
12
- id: "efe07b97-f6fb-4b6a-ba92-b68519320b2c",
13
- name: "main_title",
14
- placeholder: "",
15
- type: ReturnQuestionType.HOST_DEFAULT,
16
- },
17
- ];
18
10
  const queryBus = mock<QueryBus>();
19
11
  const signal = mock<AbortSignal>();
20
12
 
21
13
  describe("listReturnQuestionsByCheckoutItemId", () => {
22
14
  it("returns return questions by checkout item id", async () => {
23
15
  const query = listReturnQuestionsByCheckoutItemId({ checkoutItemId });
24
- const view = jest.fn(() => Promise.resolve(returnQuestionsProjection));
16
+ const view = jest.fn(() => Promise.resolve(returnQuestions));
25
17
 
26
- const returnQuestionsProjectionResult = await sut({ view, queryBus, signal })(query);
18
+ const returnQuestionsResult = await sut({ view, queryBus, signal })(query);
27
19
 
28
- expect(returnQuestionsProjectionResult).toBe(returnQuestionsProjection);
20
+ expect(returnQuestionsResult).toBe(returnQuestions);
29
21
  });
30
22
  });
@@ -0,0 +1,10 @@
1
+ enum ReturnQuestionType {
2
+ HOST_DEFAULT = "HOST_DEFAULT",
3
+ HOST_TEXTAREA = "HOST_TEXTAREA",
4
+ HOST_SELECT = "HOST_SELECT",
5
+ HOST_STACK = "HOST_STACK",
6
+ TEXTAREA = "TEXTAREA",
7
+ OPTION = "OPTION",
8
+ }
9
+
10
+ export { ReturnQuestionType };
@@ -0,0 +1,17 @@
1
+ import { EmptyObject } from "@lookiero/sty-psp-typescript";
2
+ import { ReturnQuestionType } from "./returnQuestion.constants";
3
+
4
+ interface ComponentPlaceholder {
5
+ readonly placeholder: string;
6
+ }
7
+
8
+ type MetadataDictionary = Record<ReturnQuestionType, EmptyObject>;
9
+
10
+ type ComponentMetadata = MetadataDictionary & {
11
+ [ReturnQuestionType.HOST_SELECT]: ComponentPlaceholder;
12
+ [ReturnQuestionType.TEXTAREA]: ComponentPlaceholder;
13
+ };
14
+
15
+ type Metadata<RQT extends ReturnQuestionType> = ComponentMetadata[RQT];
16
+
17
+ export type { Metadata };
@@ -1,20 +1,42 @@
1
- enum ReturnQuestionType {
2
- HOST_DEFAULT = "HOST_DEFAULT",
3
- HOST_TEXTAREA = "HOST_TEXTAREA",
4
- HOST_SELECT = "HOST_SELECT",
5
- HOST_STACK = "HOST_STACK",
6
- TEXTAREA = "TEXTAREA",
7
- OPTION = "OPTION",
8
- // ICON = "ICON",
9
- }
10
-
11
- interface ReturnQuestionProjection {
12
- readonly id: string;
13
- readonly name: string;
14
- readonly placeholder: string; // required for ReturnQuestionType.SELECT | ReturnQuestionType.TEXTAREA
15
- readonly type: ReturnQuestionType;
16
- readonly children?: ReturnQuestionProjection[];
17
- }
18
-
19
- export { ReturnQuestionType };
20
- export type { ReturnQuestionProjection };
1
+ import { EmptyObject, ExcludePropertyIfOptional, NonEmptyArray } from "@lookiero/sty-psp-typescript";
2
+ import { ReturnQuestionType } from "./returnQuestion.constants";
3
+ import { Metadata } from "./returnQuestion.metadata";
4
+
5
+ type ReturnQuestionTypesWithChildren =
6
+ | ReturnQuestionType.HOST_DEFAULT
7
+ | ReturnQuestionType.HOST_SELECT
8
+ | ReturnQuestionType.HOST_STACK
9
+ | ReturnQuestionType.HOST_TEXTAREA;
10
+
11
+ type ReturnQuestionTypesWithOptionalChildren = ReturnQuestionType.OPTION;
12
+
13
+ type ReturnQuestionTypesWithOptionalTranslationKeys = ReturnQuestionType.HOST_STACK;
14
+
15
+ type ReturnQuestionMetadata<RQT extends ReturnQuestionType> = ExcludePropertyIfOptional<
16
+ "metadata",
17
+ { readonly metadata: Metadata<RQT> }
18
+ >;
19
+
20
+ type ReturnQuestionChildren<RQT extends ReturnQuestionType> = RQT extends ReturnQuestionTypesWithChildren
21
+ ? { readonly children: NonEmptyArray<ReturnQuestion> }
22
+ : RQT extends ReturnQuestionTypesWithOptionalChildren
23
+ ? { readonly children?: NonEmptyArray<ReturnQuestion> }
24
+ : EmptyObject;
25
+
26
+ type ReturnQuestionTranslationKey<RQT extends ReturnQuestionType> =
27
+ RQT extends ReturnQuestionTypesWithOptionalTranslationKeys
28
+ ? { readonly translationKey?: string }
29
+ : { readonly translationKey: string };
30
+
31
+ type ReturnQuestion<RQT extends ReturnQuestionType = ReturnQuestionType> = RQT extends infer K extends
32
+ ReturnQuestionType
33
+ ? { readonly id: string; readonly type: K } & ReturnQuestionTranslationKey<K> &
34
+ ReturnQuestionChildren<K> &
35
+ ReturnQuestionMetadata<K>
36
+ : never;
37
+
38
+ export type {
39
+ ReturnQuestion as ReturnQuestionProjection,
40
+ ReturnQuestionTypesWithOptionalTranslationKeys,
41
+ ReturnQuestionTypesWithChildren,
42
+ };
@@ -0,0 +1,24 @@
1
+ import {
2
+ ReturnQuestionProjection,
3
+ ReturnQuestionTypesWithChildren,
4
+ ReturnQuestionTypesWithOptionalTranslationKeys,
5
+ } from "./returnQuestion";
6
+ import { ReturnQuestionType } from "./returnQuestion.constants";
7
+
8
+ const returnQuestionWithTranslationKey = (
9
+ question: ReturnQuestionProjection,
10
+ ): question is ReturnQuestionProjection<Exclude<ReturnQuestionType, ReturnQuestionTypesWithOptionalTranslationKeys>> =>
11
+ Boolean(question.translationKey);
12
+
13
+ const returnQuestionHasChildren = (
14
+ question: ReturnQuestionProjection,
15
+ ): question is ReturnQuestionProjection<ReturnQuestionTypesWithChildren> =>
16
+ [
17
+ ReturnQuestionType.HOST_DEFAULT,
18
+ ReturnQuestionType.HOST_SELECT,
19
+ ReturnQuestionType.HOST_STACK,
20
+ ReturnQuestionType.HOST_TEXTAREA,
21
+ ReturnQuestionType.OPTION,
22
+ ].includes(question.type);
23
+
24
+ export { returnQuestionWithTranslationKey, returnQuestionHasChildren };