Skip to content

Commit e46d9df

Browse files
authored
Merge pull request #1374 from AppQuality/develop
Release 20250707
2 parents 954271a + 59141e5 commit e46d9df

196 files changed

Lines changed: 1533 additions & 761 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/common/Track.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,24 @@ export const Track = ({
5555
company: activeWorkspace.company,
5656
});
5757

58-
track('unguess_loaded', {
59-
role: userData.role,
60-
customer_role: userData.customer_role,
61-
wp_user_id: userData.tryber_wp_user_id,
62-
tester_id: userData.profile_id,
63-
name: userData.name,
64-
email: userData.email,
65-
company: activeWorkspace.company,
66-
});
58+
track(
59+
'unguess_loaded',
60+
{
61+
role: userData.role,
62+
customer_role: userData.customer_role,
63+
wp_user_id: userData.tryber_wp_user_id,
64+
tester_id: userData.profile_id,
65+
name: userData.name,
66+
email: userData.email,
67+
company: activeWorkspace.company,
68+
},
69+
{
70+
plugins: {
71+
// disable track event for segment
72+
segment: false,
73+
},
74+
}
75+
);
6776
}
6877
}, [userData, activeWorkspace]);
6978

src/common/components/PlanCreationInterface/ProjectDropdown.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import { useTranslation } from 'react-i18next';
99
import { useLocation, useParams } from 'react-router-dom';
1010
import { appTheme } from 'src/app/theme';
1111
import { ReactComponent as FolderIcon } from 'src/assets/icons/folder-icon.svg';
12-
import {
13-
useGetWorkspacesByWidProjectsQuery,
14-
usePostProjectsMutation,
15-
} from 'src/features/api';
12+
import { usePostProjectsMutation } from 'src/features/api';
1613
import { useActiveWorkspace } from 'src/hooks/useActiveWorkspace';
14+
import { useActiveWorkspaceProjects } from 'src/hooks/useActiveWorkspaceProjects';
1715
import { useCanAccessToActiveWorkspace } from 'src/hooks/useCanAccessToActiveWorkspace';
1816
import { usePlanCreationContext } from './Context';
1917

@@ -25,9 +23,7 @@ export const ProjectDropdown = () => {
2523
const { projectId: pid } = useParams();
2624
const { projectId, setProjectId, fieldIsTouched, setFieldIsTouched } =
2725
usePlanCreationContext();
28-
const { data, isLoading, isFetching } = useGetWorkspacesByWidProjectsQuery({
29-
wid: activeWorkspace?.id.toString() || '',
30-
});
26+
const { data, isLoading, isFetching } = useActiveWorkspaceProjects();
3127
const [createProject] = usePostProjectsMutation();
3228
const projects = data?.items;
3329
const hasValidationError = useMemo(

src/features/modules/useModule.ts

Lines changed: 2 additions & 224 deletions
Original file line numberDiff line numberDiff line change
@@ -42,230 +42,8 @@ export const useModule = <T extends components['schemas']['Module']['type']>(
4242
dispatch(removeModule(moduleName));
4343
}, [moduleName]);
4444

45-
const getConfig = (
46-
type: components['schemas']['Module']['type']
47-
): components['schemas']['Module'] | null => {
48-
switch (type) {
49-
case 'dates':
50-
return {
51-
type,
52-
variant: 'default',
53-
output: {
54-
start: '',
55-
},
56-
};
57-
case 'goal':
58-
return {
59-
type,
60-
variant: 'default',
61-
output: '',
62-
};
63-
case 'out_of_scope':
64-
return {
65-
type,
66-
variant: 'default',
67-
output: '',
68-
};
69-
case 'title':
70-
return {
71-
type,
72-
variant: 'default',
73-
output: '',
74-
};
75-
case 'tasks':
76-
return {
77-
type,
78-
variant: 'default',
79-
output: [],
80-
};
81-
case 'age':
82-
return {
83-
type,
84-
variant: 'default',
85-
output: [
86-
{
87-
min: 16,
88-
max: 17,
89-
percentage: 0,
90-
},
91-
{
92-
min: 18,
93-
max: 24,
94-
percentage: 0,
95-
},
96-
{
97-
min: 25,
98-
max: 34,
99-
percentage: 0,
100-
},
101-
{
102-
min: 35,
103-
max: 54,
104-
percentage: 0,
105-
},
106-
{
107-
min: 55,
108-
max: 70,
109-
percentage: 0,
110-
},
111-
],
112-
};
113-
case 'gender':
114-
return {
115-
type,
116-
variant: 'default',
117-
output: [
118-
{ gender: 'male', percentage: 50 },
119-
{ gender: 'female', percentage: 50 },
120-
],
121-
};
122-
case 'literacy':
123-
return {
124-
type,
125-
variant: 'default',
126-
output: [
127-
{ level: 'beginner', percentage: 33.33 },
128-
{ level: 'intermediate', percentage: 33.33 },
129-
{ level: 'expert', percentage: 33.33 },
130-
],
131-
};
132-
case 'language':
133-
return {
134-
type,
135-
variant: 'default',
136-
output: 'en',
137-
};
138-
case 'locality':
139-
return {
140-
type,
141-
variant: 'default',
142-
output: [
143-
{
144-
type: 'country',
145-
values: ['IT'],
146-
},
147-
],
148-
};
149-
case 'target':
150-
return {
151-
type,
152-
variant: 'default',
153-
output: 5,
154-
};
155-
case 'browser':
156-
return {
157-
type,
158-
variant: 'default',
159-
output: [
160-
{ name: 'chrome', percentage: 25 },
161-
{ name: 'firefox', percentage: 25 },
162-
{ name: 'safari', percentage: 25 },
163-
{ name: 'edge', percentage: 25 },
164-
],
165-
};
166-
case 'setup_note':
167-
return {
168-
type,
169-
variant: 'default',
170-
output: '',
171-
};
172-
case 'target_note':
173-
return {
174-
type,
175-
variant: 'default',
176-
output: '',
177-
};
178-
case 'instruction_note':
179-
return {
180-
type,
181-
variant: 'default',
182-
output: '',
183-
};
184-
case 'touchpoints':
185-
return {
186-
type,
187-
variant: 'default',
188-
output: [],
189-
};
190-
case 'additional_target':
191-
return {
192-
type,
193-
variant: 'default',
194-
output: '',
195-
};
196-
case 'employment':
197-
return {
198-
type,
199-
variant: 'default',
200-
output: [],
201-
};
202-
case 'annual_income_range':
203-
return {
204-
type,
205-
variant: 'default',
206-
output: [
207-
{
208-
min: 0,
209-
max: 25000,
210-
percentage: 0,
211-
},
212-
{
213-
min: 25001,
214-
max: 50000,
215-
percentage: 0,
216-
},
217-
{
218-
min: 50001,
219-
max: 999999999,
220-
percentage: 0,
221-
},
222-
],
223-
};
224-
case 'bank':
225-
return {
226-
type,
227-
variant: 'default',
228-
output: [],
229-
};
230-
case 'elettricity_supply':
231-
return {
232-
type,
233-
variant: 'default',
234-
output: [],
235-
};
236-
case 'gas_supply':
237-
return {
238-
type,
239-
variant: 'default',
240-
output: [],
241-
};
242-
case 'mobile_internet':
243-
return {
244-
type,
245-
variant: 'default',
246-
output: [],
247-
};
248-
case 'home_internet':
249-
return {
250-
type,
251-
variant: 'default',
252-
output: [],
253-
};
254-
default:
255-
return null;
256-
}
257-
};
258-
259-
const add = () => {
260-
if (!getConfig(moduleName)) return;
261-
262-
const newModule = getConfig(moduleName);
263-
if (!newModule) return;
264-
dispatch(setModule({ type: moduleName, module: newModule }));
265-
};
266-
26745
return useMemo(
268-
() => ({ value: module, set, remove, setOutput, setVariant, add }),
269-
[module, set, remove, add]
46+
() => ({ value: module, set, remove, setOutput, setVariant }),
47+
[module, set, remove]
27048
);
27149
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useMemo } from 'react';
2+
import { useAppDispatch, useAppSelector } from 'src/app/hooks';
3+
import { components } from 'src/common/schema';
4+
import { getModuleBySlug } from 'src/pages/Plan/modules/Factory';
5+
import { setModule } from '../planModules';
6+
7+
type ModuleByType<T extends components['schemas']['Module']['type']> = Extract<
8+
components['schemas']['Module'],
9+
{ type: T }
10+
>;
11+
export const useModuleAdd = <T extends components['schemas']['Module']['type']>(
12+
moduleName: T
13+
) => {
14+
const dispatch = useAppDispatch();
15+
const module = useAppSelector(
16+
(state) => state.planModules.records[`${moduleName}`]
17+
);
18+
19+
const getConfig = (type: T): ModuleByType<T> =>
20+
({
21+
type,
22+
variant: getModuleBySlug(type)?.defaultVariant,
23+
output: getModuleBySlug(type)?.defaultData,
24+
} as ModuleByType<T>);
25+
26+
const add = () => {
27+
if (!getConfig(moduleName)) return;
28+
29+
const newModule = getConfig(moduleName);
30+
if (!newModule) return;
31+
dispatch(setModule({ type: moduleName, module: newModule }));
32+
};
33+
34+
return useMemo(() => ({ add }), [module, add]);
35+
};

src/hooks/useActiveWorkspaceProjects.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ const useActiveWorkspaceProjects = () => {
55
const { activeWorkspace } = useActiveWorkspace();
66

77
const { data, isLoading, isFetching, isError } =
8-
useGetWorkspacesByWidProjectsQuery({
9-
wid: activeWorkspace?.id.toString() || '',
10-
});
8+
useGetWorkspacesByWidProjectsQuery(
9+
{
10+
wid: activeWorkspace?.id.toString() || '',
11+
},
12+
{
13+
skip: !activeWorkspace?.id,
14+
}
15+
);
1116
// If there is no active workspace, we return an empty object
1217
if (!activeWorkspace)
1318
return {

src/pages/Campaign/MoveCampaignModal.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ import { appTheme } from 'src/app/theme';
1919
import { ReactComponent as RightArrow } from 'src/assets/icons/arrow-right.svg';
2020
import {
2121
useGetCampaignsByCidQuery,
22-
useGetWorkspacesByWidProjectsQuery,
2322
usePatchCampaignsByCidMutation,
2423
} from 'src/features/api';
25-
import { useActiveWorkspace } from 'src/hooks/useActiveWorkspace';
24+
import { useActiveWorkspaceProjects } from 'src/hooks/useActiveWorkspaceProjects';
2625
import { useSendGTMevent } from 'src/hooks/useGTMevent';
2726

2827
const MoveCampaignModalContext = createContext<{
@@ -69,14 +68,11 @@ const MoveCampaignModal = ({ campaignId }: { campaignId: string }) => {
6968
const { isOpen, setIsOpen } = useMoveCampaignModalContext();
7069

7170
const { t } = useTranslation();
72-
const { activeWorkspace } = useActiveWorkspace();
7371
const [selectedProjectId, setSelectedProjectId] = useState<number>();
7472
const [patchCampaign] = usePatchCampaignsByCidMutation();
7573
const { addToast } = useToast();
7674

77-
const { data, isLoading, isFetching } = useGetWorkspacesByWidProjectsQuery({
78-
wid: activeWorkspace?.id.toString() || '',
79-
});
75+
const { data, isLoading, isFetching } = useActiveWorkspaceProjects();
8076

8177
const sendGTMEvent = useSendGTMevent();
8278

0 commit comments

Comments
 (0)