diff --git a/src/components/ConfigureNodeFormModal/Hysteria2Form.tsx b/src/components/ConfigureNodeFormModal/Hysteria2Form.tsx new file mode 100644 index 00000000..8771a4d5 --- /dev/null +++ b/src/components/ConfigureNodeFormModal/Hysteria2Form.tsx @@ -0,0 +1,58 @@ +import { Checkbox, NumberInput, TextInput } from '@mantine/core' +import { useForm, zodResolver } from '@mantine/form' +import { useTranslation } from 'react-i18next' +import { z } from 'zod' + +import { FormActions } from '~/components/FormActions' +import { DEFAULT_HYSTERIA2_FORM_VALUES, hysteria2Schema } from '~/constants' +import { generateHysteria2URL } from '~/utils' + +export const Hysteria2Form = ({ onLinkGeneration }: { onLinkGeneration: (link: string) => void }) => { + const { t } = useTranslation() + const { onSubmit, getInputProps, reset } = useForm>({ + initialValues: DEFAULT_HYSTERIA2_FORM_VALUES, + validate: zodResolver(hysteria2Schema), + }) + + const handleSubmit = onSubmit((values) => { + /* hysteria2://[auth@]hostname[:port]/?[key=value]&[key=value]... */ + const query = { + obfs: values.obfs, + obfsPassword: values.obfsPassword, + sni: values.sni, + insecure: values.allowInsecure, + pinSHA256: values.pinSHA256, + } + + return onLinkGeneration( + generateHysteria2URL({ + protocol: 'hysteria2', + auth: values.auth, + host: values.server, + port: values.port, + params: query, + }), + ) + }) + + return ( +
+ + + + + {/* The obfuscation feature has not been implemented yet +