type search

This commit is contained in:
rizky 2024-08-28 17:24:36 -07:00
parent d85555c07e
commit 0d540214ea
6 changed files with 58 additions and 10 deletions

View File

@ -96,7 +96,6 @@ const Datepicker: React.FC<DatepickerType> = ({
if (newDate.isSame(reformatDate) || newDate.isAfter(reformatDate)) { if (newDate.isSame(reformatDate) || newDate.isAfter(reformatDate)) {
setSecondDate(nextMonth(date)); setSecondDate(nextMonth(date));
} }
console.log(date)
setFirstDate(date); setFirstDate(date);
}, },
[secondDate] [secondDate]
@ -150,7 +149,6 @@ const Datepicker: React.FC<DatepickerType> = ({
const changeSecondMonth = useCallback( const changeSecondMonth = useCallback(
(month: number) => { (month: number) => {
console.log("ALOO")
secondGotoDate( secondGotoDate(
dayjs(`${secondDate.year()}-${month < 10 ? "0" : ""}${month}-01`) dayjs(`${secondDate.year()}-${month < 10 ? "0" : ""}${month}-01`)
); );

View File

@ -15,7 +15,7 @@ const prepForSum = (obj: any): any => {
const new_obj: any = {}; const new_obj: any = {};
if (obj) { if (obj) {
for (const [k, v] of Object.entries(obj) as any) { for (const [k, v] of Object.entries(obj) as any) {
if (typeof v === "object" && v.id) { if (typeof v === "object" && v?.id) {
new_obj[k] = v.id; new_obj[k] = v.id;
continue; continue;
} }
@ -86,7 +86,7 @@ export const Field: FC<FieldProp> = (arg) => {
} }
if (arg.on_change) { if (arg.on_change) {
arg.on_change({ value: fm.data[name], name, fm }); arg.on_change({ value: fm.data?.[name], name, fm });
} }
if (fm.deps.md) { if (fm.deps.md) {

View File

@ -135,7 +135,7 @@ export const FieldInput: FC<{
{prefix && prefix !== "" ? ( {prefix && prefix !== "" ? (
<div <div
className={cx( className={cx(
"c-pl-2 c-flex c-flex-row c-items-center", "c-px-2 c-flex c-flex-row c-items-center",
css` css`
color: gray; color: gray;
` `
@ -174,6 +174,7 @@ export const FieldInput: FC<{
arg={arg} arg={arg}
prop={ prop={
{ {
placeholder: arg.placeholder,
type: type_field as any, type: type_field as any,
sub_type: arg.sub_type, sub_type: arg.sub_type,
model_upload: arg.model_upload, model_upload: arg.model_upload,
@ -199,7 +200,7 @@ export const FieldInput: FC<{
{suffix && suffix !== "" ? ( {suffix && suffix !== "" ? (
<div <div
className={cx( className={cx(
"c-pr-2 c-flex c-flex-row c-items-center", "c-px-2 c-flex c-flex-row c-items-center",
css` css`
color: gray; color: gray;
` `

View File

@ -83,6 +83,8 @@ export const TableEdit: FC<{
frozen: true, frozen: true,
renderCell(arg: any) { renderCell(arg: any) {
const { props, tbl } = arg; const { props, tbl } = arg;
local.tbl = tbl;
const key = props.column.key;
return ( return (
<PassProp <PassProp
idx={props.rowIdx} idx={props.rowIdx}
@ -92,7 +94,9 @@ export const TableEdit: FC<{
value: props.row[props.column.key], value: props.row[props.column.key],
depth: props.row.__depth || 0, depth: props.row.__depth || 0,
}} }}
fm={arg.fm} rows={tbl.data}
fm={props.fm}
fm_parent={parent}
ext_fm={{ ext_fm={{
idx: props.rowIdx, idx: props.rowIdx,
change: () => {}, change: () => {},

View File

@ -52,6 +52,10 @@ export const FieldTypeInput: FC<{
show_pass: false, show_pass: false,
change_timeout: null as any, change_timeout: null as any,
}); });
const internal = useLocal({
render_timeout: null as any,
search_timeout: null as any,
});
let type_field = prop.sub_type; let type_field = prop.sub_type;
switch (type_field) { switch (type_field) {
case "datetime": case "datetime":
@ -334,6 +338,46 @@ export const FieldTypeInput: FC<{
/> />
); );
} }
case "search": {
return (
<div className={cx("search-all c-flex items-center")}>
<div className="c-pl-2">
<svg
xmlns="http://www.w3.org/2000/svg"
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<circle cx="11" cy="11" r="8" />
<path d="m21 21-4.3-4.3" />
</svg>
</div>
<input
type="search"
placeholder={prop.placeholder}
spellCheck={false}
className="c-flex-1 c-transition-all c-bg-transparent c-outline-none c-px-2 c-text-sm c-w-full"
onChange={async (ev) => {
fm.data[field.name] = ev.currentTarget.value;
renderOnChange();
if (prop.onChange) {
await prop.onChange(fm.data[field.name]);
}
clearTimeout(internal.search_timeout);
internal.search_timeout = setTimeout(() => {
fm?.submit();
}, 1500);
}}
/>
</div>
);
}
} }
return ( return (
<div className="c-flex c-relative c-flex-1"> <div className="c-flex c-relative c-flex-1">

View File

@ -37,7 +37,7 @@ export const FieldUploadSingle: FC<{
try { try {
file = event.target?.files?.[0]; file = event.target?.files?.[0];
} catch (ex) {} } catch (ex) {}
if (prop.model_upload === "import") { if (prop.sub_type === "import") {
const reader = new FileReader(); const reader = new FileReader();
function arrayBufferToBinaryString(buffer: ArrayBuffer): string { function arrayBufferToBinaryString(buffer: ArrayBuffer): string {
@ -149,7 +149,8 @@ export const FieldUploadSingle: FC<{
ref={(ref) => (input.ref = ref)} ref={(ref) => (input.ref = ref)}
type="file" type="file"
multiple={false} multiple={false}
accept={field.prop.upload?.accept} // accept={field.prop.upload?.accept}
accept={"file/**"}
onChange={on_upload} onChange={on_upload}
className={cx( className={cx(
"c-absolute c-w-full c-h-full c-cursor-pointer c-top-0 c-left-0 c-opacity-0" "c-absolute c-w-full c-h-full c-cursor-pointer c-top-0 c-left-0 c-opacity-0"