Skip to content

Commit

Permalink
fix: style error fix
Browse files Browse the repository at this point in the history
Co-authored-by: Minseok Choi <[email protected]>
  • Loading branch information
minsgy and minsgy committed Jun 12, 2024
1 parent e19c0d8 commit 4bec014
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions example/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const handlers = [
status: 200,
description: "Success",
response: {
firstName: "John",
lastName: "Maverick",
firstName: "",
lastName: "앜코",
},
},
{
Expand Down
5 changes: 2 additions & 3 deletions src/features/DevtoolsHandlerList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { HandlerSelect } from "./HandlerSelect"
import { Button } from "@/shared/ui/button"
import { Switch } from "@/shared/ui/switch"
import {
TableCaption,
TableHeader,
TableRow,
TableHead,
Expand All @@ -31,7 +30,6 @@ export const DevtoolsHandlerList = () => {

return (
<Table>
<TableCaption>A list of your recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead className="w-[100px]">Methods</TableHead>
Expand All @@ -53,11 +51,12 @@ export const DevtoolsHandlerList = () => {
<TableCell>
<div className="flex items-center">
<HandlerSelect
value={route.selectedHandlerId}
onValueChange={(handlerId) =>
onSelectHandler(route.id, handlerId)
}
options={route.handlers}
defaultValue={route.handlers?.[0]?.id ?? undefined}
defaultValue={route.selectedHandlerId ?? route.handlers[0].id}
/>
{route.origin === "custom" && (
<InlineCode>{route.origin}</InlineCode>
Expand Down
7 changes: 7 additions & 0 deletions src/features/RouteEditPanel/EditHandlerForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
Expand All @@ -13,6 +14,7 @@ import { Input } from "@/shared/ui/input"
import { Separator } from "@/shared/ui/separator"
import { Button } from "@/shared/ui/button"
import { formattedJson } from "./utils/formattedJson"
import { InlineCode } from "@/shared/ui/typography"

export const EditHandlerForm = () => {
const handlerForm = useFormContext<CreateHandlerFormValues>()
Expand Down Expand Up @@ -72,6 +74,7 @@ export const EditHandlerForm = () => {
try {
const formattedResponse = await formattedJson(field.value)
field.onChange(formattedResponse)
handlerForm.clearErrors(`response`)
} catch (error) {
const formattedError =
error instanceof Error ? error.message : "Unknown Error"
Expand All @@ -82,6 +85,10 @@ export const EditHandlerForm = () => {
}}
/>
</FormControl>
<FormDescription>
You can use the <InlineCode>Ctrl + S</InlineCode> shortcut to save
the JSON formatting.
</FormDescription>
</FormItem>
)}
/>
Expand Down
1 change: 1 addition & 0 deletions src/features/RouteEditPanel/ResponseJsonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const ResponseJsonEditor = ({
history: true,
bracketMatching: true,
}}
onBlur={() => onSave?.()}
{...rest}
/>
)
Expand Down
8 changes: 4 additions & 4 deletions src/features/RouteEditPanel/hooks/useCreateEditFormState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
useEditorRouteState,
useRoute,
} from "@/providers/useMswDevtoolsContext"
import { useEditorPanelState } from "@/hooks/useEditorPanelState"
import { formattedJson } from "../utils/formattedJson"

export type CreateRouteFormValues = z.infer<typeof createRouteFormSchema>
Expand Down Expand Up @@ -39,13 +38,13 @@ const createRouteFormSchema = z.object({

export const useCreateEditFormState = () => {
const defaultHandler = getDefaultResponse(0)
const { selectedRoute } = useEditorRouteState()
const { selectedRoute, onCloseEditPanel } = useEditorRouteState()
const { onAddHandler, onUpdateHandler } = useRoute()
const { setIsOpenEditorPanel } = useEditorPanelState()
const routeForm = useForm<CreateRouteFormValues>({
resolver: zodResolver(createRouteFormSchema),
mode: "onSubmit",
reValidateMode: "onSubmit",
shouldUnregister: false,
defaultValues: {
delay: 0,
url: "",
Expand Down Expand Up @@ -75,9 +74,10 @@ export const useCreateEditFormState = () => {
if (selectedRoute === null) {
onAddHandler(values)
} else {
console.log("selectedRoute.id", selectedRoute.id, values)
onUpdateHandler(selectedRoute.id, values)
}
setIsOpenEditorPanel(false)
onCloseEditPanel()
}

const handleHandlerFormSubmit = (values: CreateHandlerFormValues) => {
Expand Down
1 change: 1 addition & 0 deletions src/features/RouteEditPanel/utils/formattedJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const formattedJson = async (field: string) => {
tabWidth: 4,
printWidth: 10,
parser: "json5",
trailingComma: "none",
plugins: [babel, prettierPluginEstree],
})
// LINK: https://github.com/prettier/prettier/issues/6360
Expand Down

0 comments on commit 4bec014

Please sign in to comment.