gitscope
← marzneshin / v0.7.0 / dashboard/src/modules/hosts/dialogs/mutation/fields/splithttp/index.tsx
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/modules/hosts/dialogs/mutation/fields/splithttp/index.tsx · TypeScript
Blame Raw
 1import {
 2    CheckboxField,
 3    FormField,
 4    FormItem,
 5    FormLabel,
 6    Switch,
 7} from "@marzneshin/common/components";
 8import { useFormContext, useWatch } from "react-hook-form";
 9import { useTranslation } from "react-i18next";
10import { SplitHttpModeField } from "./mode";
11import { SplitHttpPaddingBytesField } from "./padding-bytes";
12import { SplitHttpXmuxFields } from "./xmux";
13
14export const SplitHttpFields = () => {
15    const { t } = useTranslation();
16    const form = useFormContext();
17    const split_http = useWatch({ name: "splithttp_settings" });
18    const isSplitHttpDisabled = split_http === null;
19
20    const updateFieldValue = (path: string, value: any) => {
21        form.setValue(path, value === "" ? null : value, {
22            shouldDirty: true,
23            shouldValidate: true,
24        });
25    };
26
27    return (
28        <FormField
29            control={form.control}
30            name="splithttp_settings"
31            render={() => (
32                <FormItem className="my-2 w-full">
33                    <FormLabel className="flex items-center justify-between">
34                        {t("split_http")}
35                        <Switch
36                            checked={!isSplitHttpDisabled}
37                            onCheckedChange={(checked) =>
38                                form.setValue(
39                                    "splithttp_settings",
40                                    checked ? { xmux: {} } : null,
41                                )
42                            }
43                        />
44                    </FormLabel>
45
46                    {!isSplitHttpDisabled && (
47                        <>
48                            <div className="grid grid-cols-2 gap-3">
49                                <SplitHttpModeField
50                                    updater={updateFieldValue}
51                                />
52                                <SplitHttpPaddingBytesField
53                                    updater={updateFieldValue}
54                                />
55                                <CheckboxField
56                                    name="splithttp_settings.no_grpc_header"
57                                    label={t("No GRPC Header")}
58                                />
59                            </div>
60                            <SplitHttpXmuxFields />
61                        </>
62                    )}
63                </FormItem>
64            )}
65        />
66    );
67};