Skip to content

Commit f5cc52f

Browse files
authored
fix: wrap experiment properties under identity object (#4582)
1 parent d7d97e2 commit f5cc52f

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/resources/selectors/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AppState,
77
Bucket,
88
Label,
9+
OrgsState,
910
RemoteDataState,
1011
ResourceType,
1112
Secret,
@@ -72,3 +73,6 @@ export const getLabels = (state: AppState, labelIDs: string[]): Label[] => {
7273

7374
export const getAllTokensResources = (state: AppState): PermissionTypes[] =>
7475
get(state, 'resources.tokens.allResources', []) || []
76+
77+
export const getAllOrgs = (state: AppState): OrgsState =>
78+
get(state, 'resources.orgs', {}) || {}

src/shared/containers/GetOrganizations.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {getQuartzMe as apiGetQuartzMe} from 'src/me/actions/thunks'
2222
import RouteToOrg from 'src/shared/containers/RouteToOrg'
2323

2424
// Selectors
25-
import {getQuartzMe} from 'src/me/selectors'
25+
import {getAllOrgs} from 'src/resources/selectors'
26+
import {getMe, getQuartzMe} from 'src/me/selectors'
2627

2728
// Constants
2829
import {CLOUD} from 'src/shared/constants'
@@ -42,12 +43,14 @@ const canAccessCheckout = (me: Me): boolean => {
4243
}
4344

4445
const GetOrganizations: FunctionComponent = () => {
45-
const status = useSelector((state: AppState) => state.resources.orgs.status)
46+
const {status, org} = useSelector(getAllOrgs)
4647
const quartzMeStatus = useSelector(
4748
(state: AppState) => state.me.quartzMeStatus
4849
)
49-
const me = useSelector(getQuartzMe)
50+
const quartzMe = useSelector(getQuartzMe)
51+
const {id: meId = '', name: email = ''} = useSelector(getMe)
5052
const dispatch = useDispatch()
53+
5154
useEffect(() => {
5255
if (status === RemoteDataState.NotStarted) {
5356
dispatch(getOrganizations())
@@ -61,16 +64,31 @@ const GetOrganizations: FunctionComponent = () => {
6164
) {
6265
dispatch(apiGetQuartzMe())
6366
}
67+
}, [dispatch, quartzMeStatus])
6468

69+
useEffect(() => {
6570
if (
6671
isFlagEnabled('credit250Experiment') &&
67-
quartzMeStatus === RemoteDataState.Done
72+
quartzMeStatus === RemoteDataState.Done &&
73+
status === RemoteDataState.Done
6874
) {
69-
const {accountCreatedAt = ''} = me
75+
const {
76+
accountType: account_type,
77+
accountCreatedAt: account_created_at = '',
78+
} = quartzMe
79+
const {id: orgId = ''} = org
7080
window.dataLayer = window.dataLayer ?? []
71-
window.dataLayer.push({accountCreatedAt})
81+
window.dataLayer.push({
82+
identity: {
83+
account_type,
84+
account_created_at,
85+
id: meId,
86+
email,
87+
organization_id: orgId,
88+
},
89+
})
7290
}
73-
}, [dispatch, me, quartzMeStatus])
91+
}, [quartzMeStatus, status]) // eslint-disable-line react-hooks/exhaustive-deps
7492

7593
return (
7694
<PageSpinner loading={status}>
@@ -89,10 +107,10 @@ const GetOrganizations: FunctionComponent = () => {
89107
/>
90108
<Route path="/orgs" component={App} />
91109
<Route exact path="/" component={RouteToOrg} />
92-
{CLOUD && canAccessCheckout(me) && (
110+
{CLOUD && canAccessCheckout(quartzMe) && (
93111
<Route path="/checkout" component={CheckoutPage} />
94112
)}
95-
{CLOUD && me?.isOperator && (
113+
{CLOUD && quartzMe?.isOperator && (
96114
<Route path="/operator" component={OperatorPage} />
97115
)}
98116
<Route component={NotFound} />

0 commit comments

Comments
 (0)