checkpoint

This commit is contained in:
rizky 2024-09-25 21:25:24 -07:00
parent 14d0db5ed0
commit 74ed45c8fd
11 changed files with 20 additions and 39 deletions

View File

@ -1,7 +1,8 @@
import { FC, useEffect, useRef, useState } from "react";
import QrScanner from "qr-scanner";
import { QrReaderType } from "./typings";
export const QrReader: FC<{ url: string }> = ({ url }) => {
export const QrReader: FC<{ onSuccess: (result: QrReaderType) => {} }> = ({ onSuccess }) => {
const scanner = useRef<QrScanner>();
const videoEl = useRef<HTMLVideoElement>(null);
const qrBoxEl = useRef<HTMLDivElement>(null);
@ -12,9 +13,6 @@ export const QrReader: FC<{ url: string }> = ({ url }) => {
// Success
const onScanSuccess = (result: QrScanner.ScanResult) => {
// console.log(result);
// navigate("/hasil/scan");
// setScannedResult(result?.data);
if (!hasScanned) {
console.log(result);
setScannedResult(result?.data);
@ -22,9 +20,7 @@ export const QrReader: FC<{ url: string }> = ({ url }) => {
scanner.current?.stop();
setTimeout(() => {
// console.log("Mencoba trigger hasil scan");
// navigate(`/hasil/scan?id_asset=${result?.data}`);
navigate(url + result?.data);
onSuccess(result);
}, 1000);
}
};

3
comps/custom/typings.ts Executable file
View File

@ -0,0 +1,3 @@
import QrScanner from "qr-scanner";
export type QrReaderType = QrScanner.ScanResult;

View File

@ -35,7 +35,6 @@ export const FilterField: FC<{
}, [filter.form]);
let show_modifier = filter.mode !== "inline";
return (
<BaseField
{...filter.form.fieldProps({

View File

@ -27,9 +27,7 @@ export const Form: FC<FMProps> = (props) => {
},
save_status: "init",
fields: {},
events: {
on_change(name: string, new_value: any) {},
},
events: null as any,
internal: {},
submit: null as any,
error: {} as any,

View File

@ -42,28 +42,6 @@ export const Field: FC<FieldProp> = (arg) => {
useEffect(() => {
if (fm.save_status === "init" || fm.status !== "ready") return;
if (local.prev_val === undefined) {
if (typeof fm.data[name] === "object" && fm.deps.md) {
const sfied = hashSum(prepForSum(fm.data[name]));
if (sfied !== local.prev_val) {
local.prev_val = sfied;
} else {
return;
}
} else {
local.prev_val = fm.data[name];
}
if (!fm.events) {
fm.events = {
on_change(name, new_value) {},
};
}
fm.events.on_change(name, fm.data[name]);
return;
}
if (local.prev_val !== fm.data[name]) {
if (typeof fm.data[name] === "object") {

View File

@ -116,7 +116,7 @@ export const FieldTypeInput: FC<{
switch (type_field) {
case "toggle":
return (
<div className="c-px-2">
<div className="c-px-2">ad
<div
className={cx(
"c-relative",

View File

@ -10,7 +10,7 @@ export const FieldMoney: FC<{
arg: FieldProp;
}> = ({ field, fm, prop, arg }) => {
let type_field = prop.sub_type;
let value: any = fm.data[field.name];
let value: any = Number(fm.data[field.name]);
const input = useLocal({
value: 0 as any,
ref: null as any,

View File

@ -183,7 +183,6 @@ export const TableList: FC<TableListProp> = ({
reloading: null as any,
reload: (arg?: { toast: boolean }) => {
if (local.reloading) return local.reloading;
local.reloading = new Promise<void>(async (done) => {
let should_toast = true;
if (arg?.toast === false) should_toast = false;

View File

@ -128,7 +128,7 @@ export const MasterDetail: FC<MDProps> = (arg) => {
md.header.render();
}, [title]);
}
// return <>MD</>
return (
<div
className={cx(

View File

@ -193,3 +193,4 @@ export { formatTime, longDate, shortDate, timeAgo } from "lib/utils/date";
export { getBasename, getPathname } from "lib/utils/pathname";
export { formatMoney } from "lib/comps/form/field/type/TypeMoney";
export {Flow} from "lib/comps/ui/flow"

View File

@ -12,7 +12,7 @@ export const FormatValue: FC<{
value: any;
name: string;
gen_fields: string[];
mode?: "money" | "datetime" | "timeago" | "date";
mode?: "money" | "datetime" | "timeago" | "date" | "monthly";
}> = (prop) => {
const { value, gen_fields, name, mode } = prop;
if (mode === "money") {
@ -25,6 +25,13 @@ export const FormatValue: FC<{
} catch (ex: any) {
return "-";
}
} else if (mode === "monthly") {
if (!value || isEmptyString(value)) return "-";
try {
return formatDate(dayjs(value), "MMMM YYYY");
} catch (ex: any) {
return "-";
}
} else if (mode === "date") {
if (!value || isEmptyString(value)) return "-";
try {