diff --git a/frontend/app/components/Client/Projects/ProjectCodeSnippet.tsx b/frontend/app/components/Client/Projects/ProjectCodeSnippet.tsx new file mode 100644 index 000000000..e48764f39 --- /dev/null +++ b/frontend/app/components/Client/Projects/ProjectCodeSnippet.tsx @@ -0,0 +1,175 @@ +import React, { useEffect, useState } from 'react'; +import { useStore } from 'App/mstore'; +import { observer } from 'mobx-react-lite'; +import { Checkbox, Loader, Toggler } from 'UI'; +import GDPR from 'App/mstore/types/gdpr'; +import cn from 'classnames'; +import stl from './projectCodeSnippet.module.css'; +import Select from 'Shared/Select'; +import CodeSnippet from 'Shared/CodeSnippet'; +import CircleNumber from 'Components/Onboarding/components/CircleNumber'; +import Project from '@/mstore/types/project'; + +interface InputModeOption { + label: string; + value: string; +} + +const inputModeOptions: InputModeOption[] = [ + { label: 'Record all inputs', value: 'plain' }, + { label: 'Ignore all inputs', value: 'obscured' }, + { label: 'Obscure all inputs', value: 'hidden' } +]; + +const inputModeOptionsMap: Record = {}; +inputModeOptions.forEach((o, i) => (inputModeOptionsMap[o.value] = i)); + +interface Props { + project: Project; +} + +const ProjectCodeSnippet: React.FC = (props: Props) => { + const { projectsStore } = useStore(); + const siteId = projectsStore.siteId; + const site = props.project; + const gdpr = site.gdpr as GDPR; + const sites = projectsStore.list; + const editGDPR = projectsStore.editGDPR; + const onSaveGDPR = projectsStore.saveGDPR; + const init = projectsStore.initProject; + const [changed, setChanged] = useState(false); + const [isAssistEnabled, setAssistEnabled] = useState(false); + const [showLoader, setShowLoader] = useState(false); + + useEffect(() => { + const currentSite = sites.find((s) => s.id === siteId); + if (currentSite) { + init(currentSite); + } + }, [init, siteId, sites]); + + const saveGDPR = () => { + setChanged(true); + void onSaveGDPR(site.id); + }; + + const onChangeSelect = (data: { name: string; value: string }) => { + editGDPR({ [data.name]: data.value }); + saveGDPR(); + }; + + const onChangeOption = (event: React.ChangeEvent) => { + const { name, checked } = event.target; + editGDPR({ [name]: checked }); + saveGDPR(); + }; + + useEffect(() => { + setShowLoader(true); + const timer = setTimeout(() => { + setShowLoader(false); + }, 200); + return () => clearTimeout(timer); + }, [isAssistEnabled]); + + return ( +
+
+
+ Choose data recording options +
+ +
+