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