Skip to content

Commit a467fba

Browse files
committed
fix: update workspace name and models
1 parent 79b1cdb commit a467fba

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/features/workspace/components/workspace-name.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useNavigate } from "react-router-dom";
1212
import { twMerge } from "tailwind-merge";
1313
import { useFormState } from "@/hooks/useFormState";
1414
import { FormButtons } from "@/components/FormButtons";
15-
import { FormEvent } from "react";
15+
import { FormEvent, useEffect } from "react";
1616

1717
export function WorkspaceName({
1818
className,
@@ -29,10 +29,14 @@ export function WorkspaceName({
2929
const formState = useFormState({
3030
workspaceName,
3131
});
32-
const { values, updateFormValues } = formState;
32+
const { values, updateFormValues, setInitialValues } = formState;
3333
const isDefault = workspaceName === "default";
3434
const isUneditable = isArchived || isPending || isDefault;
3535

36+
useEffect(() => {
37+
setInitialValues({ workspaceName });
38+
}, [setInitialValues, workspaceName]);
39+
3640
const handleSubmit = (event: FormEvent) => {
3741
event.preventDefault();
3842

src/features/workspace/hooks/use-muxing-rules-form-workspace.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,41 @@ import { v4 as uuidv4 } from "uuid";
55

66
export type PreferredMuxRule = MuxRule & { id: string };
77

8+
type MuxingRulesFormState = {
9+
rules: PreferredMuxRule[];
10+
};
11+
812
const DEFAULT_STATE: PreferredMuxRule = {
9-
id: "",
13+
id: uuidv4(),
1014
provider_id: "",
1115
model: "",
1216
matcher: "",
1317
matcher_type: MuxMatcherType.CATCH_ALL,
1418
};
1519

1620
export const useMuxingRulesFormState = (initialValues: MuxRule[]) => {
17-
const formState = useFormState<{
18-
rules: PreferredMuxRule[];
19-
}>({
21+
const formState = useFormState<MuxingRulesFormState>({
2022
rules: [{ ...DEFAULT_STATE, id: uuidv4() }],
2123
});
2224
const { values, updateFormValues, setInitialValues } = formState;
2325

2426
useEffect(() => {
25-
if (initialValues.length === 0) return;
2627
setInitialValues({
27-
rules: initialValues.map((item) => ({ ...item, id: uuidv4() })),
28+
rules:
29+
initialValues.length == 0
30+
? [DEFAULT_STATE]
31+
: initialValues.map((item) => ({ ...item, id: uuidv4() })),
2832
});
2933
}, [initialValues, setInitialValues]);
3034

3135
const addRule = useCallback(() => {
36+
const newRules = [
37+
...values.rules.slice(0, values.rules.length - 1),
38+
{ ...DEFAULT_STATE, id: uuidv4() },
39+
...values.rules.slice(values.rules.length - 1),
40+
];
3241
updateFormValues({
33-
rules: [...values.rules, { ...DEFAULT_STATE, id: uuidv4() }],
42+
rules: newRules,
3443
});
3544
}, [updateFormValues, values.rules]);
3645

0 commit comments

Comments
 (0)