Skip to content

Commit a206f96

Browse files
authored
Merge pull request #1433 from AppQuality/UN-1803-Modifica-Copy-Status
update plan status handling and localization, add usePlanStatusLabel hook
2 parents 0936337 + ab29a66 commit a206f96

25 files changed

+151
-106
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"dependencies": {
66
"@analytics/google-tag-manager": "^0.6.0",
77
"@appquality/languages": "1.4.3",
8-
"@appquality/unguess-design-system": "4.0.49",
8+
"@appquality/unguess-design-system": "4.0.50--canary.549.a1152e0.0",
99
"@atlaskit/pragmatic-drag-and-drop": "^1.7.4",
1010
"@atlaskit/pragmatic-drag-and-drop-flourish": "^2.0.3",
1111
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.1.0",

src/pages/Plan/hooks/usePlan.ts renamed to src/hooks/usePlan.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,7 @@ import {
66
useGetCampaignsByCidQuery,
77
} from 'src/features/api';
88
import { useActiveWorkspace } from 'src/hooks/useActiveWorkspace';
9-
10-
export type PlanComposedStatusType =
11-
| 'UnquotedDraft'
12-
| 'PrequotedDraft'
13-
| 'PurchasableDraft'
14-
| 'Submitted'
15-
| 'OpsCheck'
16-
| 'AwaitingApproval'
17-
| 'Accepted'
18-
| 'RunningPlan'
19-
| 'AwaitingPayment'
20-
| 'Paying'
21-
| 'PurchasedPlan';
9+
import { PlanComposedStatusType } from 'src/types';
2210

2311
const usePlan = (planId?: string) => {
2412
const { activeWorkspace } = useActiveWorkspace();
@@ -119,7 +107,7 @@ const usePlan = (planId?: string) => {
119107
default:
120108
throw new Error(`Unknown plan status for plan: ${plan.id}`);
121109
}
122-
}, [plan, ci]);
110+
}, [plan, ci, planCampaign, planTemplate]);
123111

124112
if (!plan) {
125113
return {

src/hooks/usePlanStatusLabel.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useTranslation } from 'react-i18next';
2+
import { PlanComposedStatusType } from 'src/types';
3+
4+
export const usePlanStatusLabel = ({
5+
planStatus,
6+
}: {
7+
planStatus?: PlanComposedStatusType;
8+
}): string => {
9+
const { t } = useTranslation();
10+
if (!planStatus) {
11+
return '';
12+
}
13+
const statusMap: Record<PlanComposedStatusType, string> = {
14+
UnquotedDraft: t('___PLAN_STATUS_UNQUOTED_DRAFT'),
15+
PrequotedDraft: t('___PLAN_STATUS_PREQUOTED_DRAFT'),
16+
PurchasableDraft: t('___PLAN_STATUS_PURCHASABLE_DRAFT'),
17+
Submitted: t('___PLAN_STATUS_SUBMITTED'),
18+
OpsCheck: t('___PLAN_STATUS_OPS_CHECK'),
19+
AwaitingApproval: t('___PLAN_STATUS_AWAITING_APPROVAL'),
20+
Accepted: t('___PLAN_STATUS_ACCEPTED'),
21+
RunningPlan: t('___PLAN_STATUS_RUNNING_PLAN'),
22+
AwaitingPayment: t('___PLAN_STATUS_AWAITING_PAYMENT'),
23+
Paying: t('___PLAN_STATUS_PAYING'),
24+
PurchasedPlan: t('___PLAN_STATUS_PURCHASED_PLAN'),
25+
};
26+
27+
return statusMap[`${planStatus}`];
28+
};

src/locales/en/translation.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
{
2+
"___PLAN_STATUS_ACCEPTED": "Accepted",
3+
"___PLAN_STATUS_AWAITING_APPROVAL": "Waiting for you",
4+
"___PLAN_STATUS_AWAITING_PAYMENT": "Waiting for you",
5+
"___PLAN_STATUS_OPS_CHECK": "Under review",
6+
"___PLAN_STATUS_PAYING": "Ongoing Payment",
7+
"___PLAN_STATUS_PREQUOTED_DRAFT": "Draft",
8+
"___PLAN_STATUS_PURCHASABLE_DRAFT": "Draft",
9+
"___PLAN_STATUS_PURCHASED_PLAN": "Accepted",
10+
"___PLAN_STATUS_RUNNING_PLAN": "Running",
11+
"___PLAN_STATUS_SUBMITTED": "Under review",
12+
"___PLAN_STATUS_UNQUOTED_DRAFT": "Draft",
213
"__404_PAGE_BUTTON": "Back to home",
314
"__404_PAGE_DESCRIPTION": "Let’s find a better place for you to go.",
415
"__404_PAGE_SUB_TITLE MAX:80": "This page could have been removed or it’s unavailable.",
@@ -1367,6 +1378,9 @@
13671378
"_CAMPAIGN_WIDGET_UX_USER_ANALYSIS_DESCRIPTION_HEADER": "There are observations on",
13681379
"_CAMPAIGN_WIDGET_UX_USER_ANALYSIS_HEADER": "Analyzed User Contributions",
13691380
"_PAGE_PROFILE_HEADER_TEXT": "Manage your profile anytime: check and update your personal information whenever you need.",
1381+
"_PLAN_CARD_LABEL_CONFIRM": "Confirm & Launch",
1382+
"_PLAN_CARD_LABEL_FINALIZE": "Finalize Activity",
1383+
"_PLAN_CARD_LABEL_LOOK": "Take a look",
13701384
"_PLAN_PAGE_MODULE_LANGUAGE_DESCRIPTION": "You’ll receive feedback in the language you’re selecting",
13711385
"_PLAN_PAGE_MODULE_LANGUAGE_SUBTITLE": "Select participants' preferred language",
13721386
"_PROJECT_PAGE_PLANS_GROUP_SEE_ALL": "View more",

src/locales/it/translation.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
{
2+
"___PLAN_STATUS_ACCEPTED": "",
3+
"___PLAN_STATUS_AWAITING_APPROVAL": "",
4+
"___PLAN_STATUS_AWAITING_PAYMENT": "",
5+
"___PLAN_STATUS_OPS_CHECK": "",
6+
"___PLAN_STATUS_PAYING": "",
7+
"___PLAN_STATUS_PREQUOTED_DRAFT": "",
8+
"___PLAN_STATUS_PURCHASABLE_DRAFT": "",
9+
"___PLAN_STATUS_PURCHASED_PLAN": "",
10+
"___PLAN_STATUS_RUNNING_PLAN": "",
11+
"___PLAN_STATUS_SUBMITTED": "",
12+
"___PLAN_STATUS_UNQUOTED_DRAFT": "",
213
"__404_PAGE_BUTTON": "Torna alla dashboard",
314
"__404_PAGE_DESCRIPTION": "La direzione giusta ora è solo una.",
415
"__404_PAGE_SUB_TITLE MAX:80": "L'abbiamo cercata ovunque ma non è disponibile.",
@@ -1409,6 +1420,9 @@
14091420
"_CAMPAIGN_WIDGET_UX_USER_ANALYSIS_DESCRIPTION_HEADER": "Hai aggiunto osservazioni su",
14101421
"_CAMPAIGN_WIDGET_UX_USER_ANALYSIS_HEADER": "Contributi utente analizzati",
14111422
"_PAGE_PROFILE_HEADER_TEXT": "",
1423+
"_PLAN_CARD_LABEL_CONFIRM": "",
1424+
"_PLAN_CARD_LABEL_FINALIZE": "",
1425+
"_PLAN_CARD_LABEL_LOOK": "",
14121426
"_PLAN_PAGE_MODULE_LANGUAGE_DESCRIPTION": "",
14131427
"_PLAN_PAGE_MODULE_LANGUAGE_SUBTITLE": "",
14141428
"_PROJECT_PAGE_PLANS_GROUP_SEE_ALL": "Vedi tutti",

src/pages/Dashboard/PlanCard.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { PlanCard as UGPlanCard } from '@appquality/unguess-design-system';
2+
import { get } from 'http';
3+
import { useTranslation } from 'react-i18next';
4+
import { useNavigate } from 'react-router-dom';
5+
import { GetWorkspacesByWidPlansApiResponse } from 'src/features/api';
6+
import { usePlan } from 'src/hooks/usePlan';
7+
import { usePlanStatusLabel } from 'src/hooks/usePlanStatusLabel';
8+
import { PlanComposedStatusType } from 'src/types';
9+
10+
export const PlanCard = ({
11+
plan,
12+
}: {
13+
plan: GetWorkspacesByWidPlansApiResponse[number];
14+
}) => {
15+
const { planComposedStatus } = usePlan(plan.id.toString());
16+
const { t } = useTranslation();
17+
const statusLabel = usePlanStatusLabel({ planStatus: planComposedStatus });
18+
const navigate = useNavigate();
19+
const navigateToPlan = () => {
20+
navigate(`/plans/${plan.id}`);
21+
};
22+
23+
const getPlanLabel = (planStatus?: PlanComposedStatusType) => {
24+
switch (planStatus) {
25+
case 'PurchasableDraft':
26+
case 'UnquotedDraft':
27+
case 'PrequotedDraft':
28+
return t('_PLAN_CARD_LABEL_FINALIZE');
29+
case 'Submitted':
30+
case 'OpsCheck':
31+
case 'Paying':
32+
return t('_PLAN_CARD_LABEL_LOOK');
33+
case 'AwaitingPayment':
34+
case 'AwaitingApproval':
35+
return t('_PLAN_CARD_LABEL_CONFIRM');
36+
default:
37+
return '';
38+
}
39+
};
40+
return (
41+
<UGPlanCard
42+
status={planComposedStatus}
43+
i18n={{ statusLabel, planLabel: getPlanLabel(planComposedStatus) }}
44+
onClick={navigateToPlan}
45+
>
46+
<UGPlanCard.ProjectLabel>{plan.project.title}</UGPlanCard.ProjectLabel>
47+
<UGPlanCard.Title>{plan.title}</UGPlanCard.Title>
48+
</UGPlanCard>
49+
);
50+
};

src/pages/Dashboard/SuggestedCampaigns.tsx

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
Col,
33
Paragraph,
4-
PlanCard,
54
Row,
65
Separator,
76
} from '@appquality/unguess-design-system';
@@ -11,8 +10,8 @@ import { ScrollingGrid } from 'src/common/components/ScrollingGrid';
1110
import { SectionTitle } from 'src/common/components/SectionTitle';
1211
import { CampaignItem } from './CampaignItem';
1312
import { CardRowLoading } from './CardRowLoading';
14-
import { getPlanStatus } from './hooks/getPlanStatus';
1513
import { useCampaignsAndPlans } from './hooks/useCampaignsAndPlans';
14+
import { PlanCard } from './PlanCard';
1615

1716
const MAX_SUGGESTED_ITEMS = 5;
1817

@@ -48,30 +47,7 @@ export const SuggestedCampaigns = () => {
4847
key={`suggested_plan_${plan.id}`}
4948
data-qa={`tracked-activity-${i}`}
5049
>
51-
<PlanCard
52-
status={
53-
getPlanStatus({
54-
planStatus: plan.status,
55-
quote: plan.quote,
56-
t,
57-
}).status
58-
}
59-
i18n={{
60-
statusLabel: getPlanStatus({
61-
planStatus: plan.status,
62-
quote: plan.quote,
63-
t,
64-
}).statusLabel,
65-
}}
66-
onClick={() => {
67-
window.location.href = `/plans/${plan.id}`;
68-
}}
69-
>
70-
<PlanCard.ProjectLabel>
71-
{plan.project.title}
72-
</PlanCard.ProjectLabel>
73-
<PlanCard.Title>{plan.title}</PlanCard.Title>
74-
</PlanCard>
50+
<PlanCard plan={plan} />
7551
</ScrollingGrid.Item>
7652
))}
7753

src/pages/Dashboard/project-items/Plans.tsx

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
Button,
3-
Col,
4-
PlanCard,
5-
Row,
6-
Separator,
7-
} from '@appquality/unguess-design-system';
1+
import { Button, Col, Row, Separator } from '@appquality/unguess-design-system';
82
import { ReactComponent as ChevronDownStroke } from '@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg';
93
import { ReactComponent as ChevronUpStroke } from '@zendeskgarden/svg-icons/src/16/chevron-up-stroke.svg';
104
import { useState } from 'react';
@@ -13,8 +7,8 @@ import { appTheme } from 'src/app/theme';
137
import { SectionTitle } from 'src/common/components/SectionTitle';
148
import { styled } from 'styled-components';
159
import { CardRowLoading } from '../CardRowLoading';
16-
import { getPlanStatus } from '../hooks/getPlanStatus';
1710
import { useProjectPlans } from '../hooks/useProjectPlans';
11+
import { PlanCard } from '../PlanCard';
1812

1913
const PREVIEW_ITEMS_MAX_SIZE = 3;
2014

@@ -65,27 +59,7 @@ export const Plans = ({ projectId }: { projectId: number }) => {
6559
key={`project_plan_${plan.id}`}
6660
data-qa={`setup-activity-${i}`}
6761
>
68-
<PlanCard
69-
status={
70-
getPlanStatus({ planStatus: plan.status, quote: plan.quote, t })
71-
.status
72-
}
73-
i18n={{
74-
statusLabel: getPlanStatus({
75-
planStatus: plan.status,
76-
quote: plan.quote,
77-
t,
78-
}).statusLabel,
79-
}}
80-
onClick={() => {
81-
window.location.href = `/plans/${plan.id}`;
82-
}}
83-
>
84-
<PlanCard.ProjectLabel>
85-
{plan.project.title}
86-
</PlanCard.ProjectLabel>
87-
<PlanCard.Title>{plan.title}</PlanCard.Title>
88-
</PlanCard>
62+
<PlanCard plan={plan} />
8963
</Col>
9064
))}
9165
</Row>

src/pages/Plan/Controls/ConfirmPlanButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useState } from 'react';
33
import { useTranslation } from 'react-i18next';
44
import { useParams } from 'react-router-dom';
55
import { usePatchPlansByPidStatusMutation } from 'src/features/api';
6-
import { usePlan } from '../hooks/usePlan';
6+
import { usePlan } from '../../../hooks/usePlan';
77
import { BuyButton } from '../summary/components/BuyButton';
88

99
const ConfirmPlanButton = () => {

src/pages/Plan/Controls/GoToCampaignButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Button } from '@appquality/unguess-design-system';
22
import { useTranslation } from 'react-i18next';
33
import { useNavigate, useParams } from 'react-router-dom';
44
import { useLocalizeRoute } from 'src/hooks/useLocalizedRoute';
5-
import { usePlan } from '../hooks/usePlan';
5+
import { usePlan } from '../../../hooks/usePlan';
66

77
const GoToCampaignButton = () => {
88
const { t } = useTranslation();

0 commit comments

Comments
 (0)