From a1ab7bc734996ebc0a34bb9f9d26a47b7470e3ec Mon Sep 17 00:00:00 2001 From: rizky Date: Wed, 21 Aug 2024 01:52:39 -0700 Subject: [PATCH] fix --- comps/form/field/Field.tsx | 1 + comps/form/field/type/TypeInput.tsx | 4 +++ comps/form/utils/init.tsx | 2 -- exports.tsx | 1 + session/server.ts | 38 ++++++++++++++++++++--------- utils/post.ts | 26 ++++++++++++++++++++ 6 files changed, 58 insertions(+), 14 deletions(-) create mode 100755 utils/post.ts diff --git a/comps/form/field/Field.tsx b/comps/form/field/Field.tsx index 97e70d3..b503611 100755 --- a/comps/form/field/Field.tsx +++ b/comps/form/field/Field.tsx @@ -135,6 +135,7 @@ export const Field: FC = (arg) => { className={cx( "field", field.type, + name, sub_type, "c-flex c-relative", editorClassName, diff --git a/comps/form/field/type/TypeInput.tsx b/comps/form/field/type/TypeInput.tsx index e646c9d..7a60bb0 100755 --- a/comps/form/field/type/TypeInput.tsx +++ b/comps/form/field/type/TypeInput.tsx @@ -246,6 +246,8 @@ export const FieldTypeInput: FC<{ prop.onChange(fm.data[field.name]); } }} + //@ts-ignore + inputmode="decimal" value={format(value, { mask: "____-____-_______", replacement: { _: /\d/ }, @@ -276,6 +278,8 @@ export const FieldTypeInput: FC<{
{ fm.data[field.name] = ev.currentTarget.value.replace(/\D/g, ""); diff --git a/comps/form/utils/init.tsx b/comps/form/utils/init.tsx index 3e87309..8b0ad7b 100755 --- a/comps/form/utils/init.tsx +++ b/comps/form/utils/init.tsx @@ -269,8 +269,6 @@ export const formInit = (fm: FMLocal, props: FMProps) => { fm.render(); } - console.clear(); - if (fm.props.sonar === "on" && !isEditor) { toast.dismiss(); diff --git a/exports.tsx b/exports.tsx index 6a279d9..191b208 100755 --- a/exports.tsx +++ b/exports.tsx @@ -106,6 +106,7 @@ export { prasi_gen } from "./gen/prasi_gen"; export { guessLabel } from "./utils/guess-label"; import __get from "lodash.get"; import { sum } from "./utils/sum"; +export { _post } from "./utils/post"; export { toast, Toaster } from "./comps/ui/toast"; export { NavLink } from "./comps/popup/NavLink"; export { kvToJSON } from "./utils/kv-to-json"; diff --git a/session/server.ts b/session/server.ts index e2c486d..eb4a6d7 100755 --- a/session/server.ts +++ b/session/server.ts @@ -1,19 +1,23 @@ /// +type ServerArg = { + req: Request; + handle: (req: Request) => Promise; + mode: "dev" | "prod"; + url: { + raw: URL; + pathname: string; + }; +}; type ServerSession = { - handle: (arg: { - req: Request; - handle: (req: Request) => Promise; - mode: "dev" | "prod"; - url: { - raw: URL; - pathname: string; - }; - }) => Promise; + handle: (arg: ServerArg) => Promise; }; export const sessionServer = (arg: { encrypt?: boolean; + router?: ( + arg: ServerArg & { session: {} } + ) => Response | (() => Promise) | void; on: { login: (arg: { mode: "user-pass"; @@ -23,9 +27,19 @@ export const sessionServer = (arg: { }; }): ServerSession => { const s: ServerSession = { - async handle({ req, handle, mode, url }) { - if (url.pathname.startsWith("/_session")) { - return new Response("marjio"); + async handle(server_arg) { + const { req, handle, mode, url } = server_arg; + if (typeof arg.router === "function") { + let result = arg.router({ + ...server_arg, + session: {}, + }); + if (result && typeof result === "function") { + result = await result(); + } + if (result instanceof Response) { + return result; + } } return await handle(req); diff --git a/utils/post.ts b/utils/post.ts new file mode 100755 index 0000000..a165cef --- /dev/null +++ b/utils/post.ts @@ -0,0 +1,26 @@ +export const _post = async ( + path: string, + data: any, + arg?: { mode: "auto" | "always-prod" } +) => { + const final_path = path.startsWith("/") ? path : `/${path}`; + + let _url = baseurl(final_path); + + if ( + location.hostname === "prasi.avolut.com" || + location.host === "localhost:4550" + ) { + if (arg?.mode === "always-prod") { + const newurl = new URL(location.href); + newurl.pathname = `/_proxy/${_url}`; + _url = newurl.toString(); + } + } + + const res = await fetch(_url, { + method: "POST", + body: JSON.stringify(data), + }); + return await res.json(); +};