-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(onboarding): add product config screen (#18720)
* stub out config screen * saave the configuration * fix * add existing replay controls to config * dont show any toasts in onboarding * add minimum duration option * move dropdown * flag the control * Update frontend/src/scenes/onboarding/Onboarding.tsx Co-authored-by: Paul D'Ambra <[email protected]> --------- Co-authored-by: Paul D'Ambra <[email protected]>
- Loading branch information
Showing
8 changed files
with
222 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
frontend/src/scenes/onboarding/OnboardingProductConfiguration.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { LemonSelect, LemonSwitch } from '@posthog/lemon-ui' | ||
import { useActions, useValues } from 'kea' | ||
import { useEffect } from 'react' | ||
|
||
import { OnboardingStepKey } from './onboardingLogic' | ||
import { onboardingProductConfigurationLogic, ProductConfigOption } from './onboardingProductConfigurationLogic' | ||
import { OnboardingStep } from './OnboardingStep' | ||
|
||
export const OnboardingProductConfiguration = ({ | ||
stepKey = OnboardingStepKey.PRODUCT_CONFIGURATION, | ||
options, | ||
}: { | ||
stepKey?: OnboardingStepKey | ||
options: ProductConfigOption[] | ||
}): JSX.Element | null => { | ||
const { configOptions } = useValues(onboardingProductConfigurationLogic) | ||
const { setConfigOptions, saveConfiguration } = useActions(onboardingProductConfigurationLogic) | ||
useEffect(() => { | ||
setConfigOptions(options) | ||
}, []) | ||
|
||
return configOptions ? ( | ||
<OnboardingStep title={`Set up your configuration`} stepKey={stepKey} continueAction={saveConfiguration}> | ||
{configOptions?.map((option: ProductConfigOption) => ( | ||
<div className="my-8" key={option.teamProperty}> | ||
{option.type == 'toggle' ? ( | ||
<> | ||
<LemonSwitch | ||
data-attr="opt-in-session-recording-switch" | ||
onChange={(checked) => { | ||
setConfigOptions( | ||
configOptions.map((o) => | ||
o.teamProperty === option.teamProperty ? { ...o, value: checked } : o | ||
) | ||
) | ||
}} | ||
label={option.title} | ||
fullWidth={true} | ||
labelClassName={'text-base font-semibold'} | ||
checked={option.value || false} | ||
/> | ||
<p className="prompt-text ml-0">{option.description}</p> | ||
</> | ||
) : ( | ||
<> | ||
<label className="text-base font-semibold">{option.title}</label> | ||
<div className="flex justify-between items-center mb-1 gap-x-4"> | ||
<p className="prompt-text m-0">{option.description}</p> | ||
<LemonSelect | ||
dropdownMatchSelectWidth={false} | ||
onChange={(v) => { | ||
setConfigOptions( | ||
configOptions.map((o) => | ||
o.teamProperty === option.teamProperty ? { ...o, value: v } : o | ||
) | ||
) | ||
}} | ||
options={option.selectOptions || []} | ||
value={option.value} | ||
/> | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
))} | ||
</OnboardingStep> | ||
) : null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
frontend/src/scenes/onboarding/onboardingProductConfigurationLogic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { LemonSelectOptions } from '@posthog/lemon-ui' | ||
import { actions, connect, kea, listeners, path, reducers } from 'kea' | ||
import { teamLogic } from 'scenes/teamLogic' | ||
|
||
import type { onboardingProductConfigurationLogicType } from './onboardingProductConfigurationLogicType' | ||
|
||
export interface ProductConfigOptionBase { | ||
title: string | ||
description: string | ||
teamProperty: string | ||
} | ||
|
||
export interface ProductConfigurationToggle extends ProductConfigOptionBase { | ||
type: 'toggle' | ||
/** Sets the initial value. Use a team setting to reflect current state, or a static value to set a default. */ | ||
value: boolean | ||
/** If true, the value is inverted when saving, used for 'opt_out' type settings */ | ||
inverseToggle?: boolean | ||
} | ||
|
||
export interface ProductConfigurationSelect extends ProductConfigOptionBase { | ||
type: 'select' | ||
/** Sets the initial value. Use a team setting to reflect current state, or a static value to set a default. */ | ||
value: string | number | null | ||
selectOptions: LemonSelectOptions<any> | ||
} | ||
|
||
export type ProductConfigOption = ProductConfigurationToggle | ProductConfigurationSelect | ||
|
||
export const onboardingProductConfigurationLogic = kea<onboardingProductConfigurationLogicType>([ | ||
path(() => ['scenes', 'onboarding', 'onboardingProductConfigurationLogic']), | ||
connect({ | ||
actions: [teamLogic, ['updateCurrentTeam']], | ||
}), | ||
actions({ | ||
setConfigOptions: (configOptions: ProductConfigOption[]) => ({ configOptions }), | ||
saveConfiguration: true, | ||
}), | ||
reducers(() => ({ | ||
configOptions: [ | ||
[], | ||
{ | ||
setConfigOptions: (_, { configOptions }) => configOptions, | ||
}, | ||
], | ||
})), | ||
listeners(({ values, actions }) => ({ | ||
saveConfiguration: async () => { | ||
const updateConfig = {} | ||
values.configOptions.forEach((configOption) => { | ||
updateConfig[configOption.teamProperty] = configOption.inverseToggle | ||
? !configOption.value | ||
: configOption.value | ||
}) | ||
actions.updateCurrentTeam(updateConfig) | ||
}, | ||
})), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters