This commit is contained in:
rizky 2024-08-21 01:52:39 -07:00
parent 72c85b75d0
commit a1ab7bc734
6 changed files with 58 additions and 14 deletions

View File

@ -135,6 +135,7 @@ export const Field: FC<FieldProp> = (arg) => {
className={cx(
"field",
field.type,
name,
sub_type,
"c-flex c-relative",
editorClassName,

View File

@ -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<{
<div className="c-flex c-relative c-flex-1">
<InputMask
mask={mask}
//@ts-ignore
inputmode="decimal"
replacement={{ _: /\d/ }}
onChange={(ev) => {
fm.data[field.name] = ev.currentTarget.value.replace(/\D/g, "");

View File

@ -269,8 +269,6 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
fm.render();
}
console.clear();
if (fm.props.sonar === "on" && !isEditor) {
toast.dismiss();

View File

@ -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";

View File

@ -1,7 +1,6 @@
/// <reference types="bun-types" />
type ServerSession = {
handle: (arg: {
type ServerArg = {
req: Request;
handle: (req: Request) => Promise<Response>;
mode: "dev" | "prod";
@ -9,11 +8,16 @@ type ServerSession = {
raw: URL;
pathname: string;
};
}) => Promise<Response>;
};
type ServerSession = {
handle: (arg: ServerArg) => Promise<Response>;
};
export const sessionServer = <T>(arg: {
encrypt?: boolean;
router?: (
arg: ServerArg & { session: {} }
) => Response | (() => Promise<Response | void>) | void;
on: {
login: (arg: {
mode: "user-pass";
@ -23,9 +27,19 @@ export const sessionServer = <T>(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);

26
utils/post.ts Executable file
View File

@ -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();
};