/* eslint-disable sonarjs/cognitive-complexity */ import '../OnboardingQuestionaire.styles.scss'; import { Color } from '@signozhq/design-tokens'; import { Button, Input, Typography } from 'antd'; import logEvent from 'api/common/logEvent'; import editOrg from 'api/user/editOrg'; import { useNotifications } from 'hooks/useNotifications'; import { ArrowRight, CheckCircle, Loader2 } from 'lucide-react'; import { useAppContext } from 'providers/App/App'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; export interface OrgData { id: string; displayName: string; } export interface OrgDetails { organisationName: string; usesObservability: boolean | null; observabilityTool: string | null; otherTool: string | null; familiarity: string | null; } interface OrgQuestionsProps { currentOrgData: OrgData | null; orgDetails: OrgDetails; onNext: (details: OrgDetails) => void; } const observabilityTools = { AWSCloudwatch: 'AWS Cloudwatch', DataDog: 'DataDog', NewRelic: 'New Relic', GrafanaPrometheus: 'Grafana / Prometheus', AzureAppMonitor: 'Azure App Monitor', GCPNativeO11yTools: 'GCP-native o11y tools', Honeycomb: 'Honeycomb', }; const o11yFamiliarityOptions: Record = { beginner: 'Beginner', intermediate: 'Intermediate', expert: 'Expert', notFamiliar: "I'm not familiar with it", }; function OrgQuestions({ currentOrgData, orgDetails, onNext, }: OrgQuestionsProps): JSX.Element { const { user, updateOrg } = useAppContext(); const { notifications } = useNotifications(); const { t } = useTranslation(['organizationsettings', 'common']); const [organisationName, setOrganisationName] = useState( orgDetails?.organisationName || '', ); const [usesObservability, setUsesObservability] = useState( orgDetails?.usesObservability || null, ); const [observabilityTool, setObservabilityTool] = useState( orgDetails?.observabilityTool || null, ); const [otherTool, setOtherTool] = useState( orgDetails?.otherTool || '', ); const [familiarity, setFamiliarity] = useState( orgDetails?.familiarity || null, ); const [isNextDisabled, setIsNextDisabled] = useState(true); useEffect(() => { setOrganisationName(orgDetails.organisationName); }, [orgDetails.organisationName]); const [isLoading, setIsLoading] = useState(false); const handleOrgNameUpdate = async (): Promise => { /* Early bailout if orgData is not set or if the organisation name is not set or if the organisation name is empty or if the organisation name is the same as the one in the orgData */ if ( !currentOrgData || !organisationName || organisationName === '' || orgDetails.organisationName === organisationName ) { logEvent('Org Onboarding: Answered', { usesObservability, observabilityTool, otherTool, familiarity, }); onNext({ organisationName, usesObservability, observabilityTool, otherTool, familiarity, }); return; } try { setIsLoading(true); const { statusCode, error } = await editOrg({ displayName: organisationName, orgId: currentOrgData.id, }); if (statusCode === 204) { updateOrg(currentOrgData?.id, organisationName); logEvent('Org Onboarding: Org Name Updated', { organisationName, }); logEvent('Org Onboarding: Answered', { usesObservability, observabilityTool, otherTool, familiarity, }); onNext({ organisationName, usesObservability, observabilityTool, otherTool, familiarity, }); } else { logEvent('Org Onboarding: Org Name Update Failed', { organisationName: orgDetails.organisationName, }); notifications.error({ message: error || t('something_went_wrong', { ns: 'common', }), }); } setIsLoading(false); } catch (error) { setIsLoading(false); notifications.error({ message: t('something_went_wrong', { ns: 'common', }), }); } }; const isValidUsesObservability = (): boolean => { if (usesObservability === null) { return false; } if (usesObservability && (!observabilityTool || observabilityTool === '')) { return false; } // eslint-disable-next-line sonarjs/prefer-single-boolean-return if (usesObservability && observabilityTool === 'Others' && otherTool === '') { return false; } return true; }; useEffect(() => { const isValidObservability = isValidUsesObservability(); if (organisationName !== '' && familiarity !== null && isValidObservability) { setIsNextDisabled(false); } else { setIsNextDisabled(true); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [ organisationName, usesObservability, familiarity, observabilityTool, otherTool, ]); const handleOnNext = (): void => { handleOrgNameUpdate(); }; return (
Welcome, {user?.name}! We'll help you get the most out of SigNoz, whether you're new to observability or a seasoned pro.
setOrganisationName(e.target.value)} />
{usesObservability && (
{Object.keys(observabilityTools).map((tool) => ( ))} {observabilityTool === 'Others' ? ( ) : ( '' ) } onChange={(e): void => setOtherTool(e.target.value)} /> ) : ( )}
)}
Are you familiar with setting up observability (o11y)?
{Object.keys(o11yFamiliarityOptions).map((option: string) => ( ))}
); } export default OrgQuestions;