import React from 'react'; import { useForm } from 'react-hook-form'; import { base16 } from 'rfc4648'; import { connection } from '@core/connection'; import { useAppSelector } from '@hooks/useAppSelector'; import { Checkbox, Input, Select } from '@meshtastic/components'; import { Protobuf } from '@meshtastic/meshtasticjs'; export const User = (): JSX.Element => { const [loading, setLoading] = React.useState(false); const myNodeNum = useAppSelector( (state) => state.meshtastic.radio.hardware, ).myNodeNum; const node = useAppSelector((state) => state.meshtastic.nodes).find( (node) => node.number === myNodeNum, ); const { register, handleSubmit, formState, reset } = useForm<{ longName: string; shortName: string; isLicensed: boolean; team: Protobuf.Team; antAzimuth: number; antGainDbi: number; txPowerDbm: number; }>({ defaultValues: { longName: node?.user?.longName, shortName: node?.user?.shortName, isLicensed: node?.user?.isLicensed, team: node?.user?.team, antAzimuth: node?.user?.antAzimuth, antGainDbi: node?.user?.antGainDbi, txPowerDbm: node?.user?.txPowerDbm, }, }); React.useEffect(() => { reset({ longName: node?.user?.longName, shortName: node?.user?.shortName, isLicensed: node?.user?.isLicensed, team: node?.user?.team, }); }, [reset, node]); const onSubmit = handleSubmit((data) => { setLoading(true); if (node?.user) { void connection.setOwner({ ...node.user, ...data }, async () => { reset({ ...data }); setLoading(false); await Promise.resolve(); }); // TODO: can be removed once getUser is implemented // dispatch( // addUser({ ...node.user, ...{ data: { ...node.user.data, ...data } } }), // ); } }); return (
); };