update Typeahead.tsx, typeahead-opt.tsx, TableList.tsx and axios.ts

This commit is contained in:
faisolavolut 2025-02-04 10:33:13 +07:00
parent ca52720715
commit 3532415aba
3 changed files with 37 additions and 26 deletions

View File

@ -513,6 +513,7 @@ export const Typeahead: FC<{
resetSearch(); resetSearch();
} }
}} }}
loading={local.loading}
showEmpty={!allow_new} showEmpty={!allow_new}
className={popupClassName} className={popupClassName}
open={local.open} open={local.open}

View File

@ -6,6 +6,7 @@ import { ButtonBetter } from "../../ui/button";
export type OptionItem = { value: string; label: string }; export type OptionItem = { value: string; label: string };
export const TypeaheadOptions: FC<{ export const TypeaheadOptions: FC<{
popup?: boolean; popup?: boolean;
loading?: boolean;
open?: boolean; open?: boolean;
children: any; children: any;
onOpenChange?: (open: boolean) => void; onOpenChange?: (open: boolean) => void;
@ -25,6 +26,7 @@ export const TypeaheadOptions: FC<{
fitur?: "search-add"; fitur?: "search-add";
}> = ({ }> = ({
popup, popup,
loading,
children, children,
open, open,
onOpenChange, onOpenChange,
@ -61,33 +63,41 @@ export const TypeaheadOptions: FC<{
` `
)} )}
> >
{options.map((item, idx) => { {!loading ? (
const is_selected = selected?.({ item, options, idx }); <>
{options.map((item, idx) => {
const is_selected = selected?.({ item, options, idx });
if (is_selected) { if (is_selected) {
local.selectedIdx = idx; local.selectedIdx = idx;
} }
return ( return (
<div <div
tabIndex={0} tabIndex={0}
key={item.value + "_" + idx} key={item.value + "_" + idx}
className={cx( className={cx(
"opt-item px-3 py-1 cursor-pointer option-item text-sm", "opt-item px-3 py-1 cursor-pointer option-item text-sm",
is_selected ? "bg-blue-600 text-white" : "hover:bg-blue-50", is_selected ? "bg-blue-600 text-white" : "hover:bg-blue-50",
idx > 0 && "border-t" idx > 0 && "border-t"
)} )}
onClick={() => { onClick={() => {
onSelect?.(item.value); onSelect?.(item.value);
}} }}
> >
{item.label || <>&nbsp;</>} {item.label || <>&nbsp;</>}
</div> </div>
); );
})} })}
</>
) : (
<></>
)}
{searching ? ( {loading || searching ? (
<div className="px-4 w-full text-slate-400">Loading...</div> <div className="px-4 w-full text-slate-400 text-sm py-2">
Loading...
</div>
) : ( ) : (
<> <>
{options.length === 0 && ( {options.length === 0 && (

View File

@ -1,12 +1,12 @@
import axios from "axios"; import axios from "axios";
import Cookies from "js-cookie"; import Cookies from "js-cookie";
import dotenv from 'dotenv'; import dotenv from "dotenv";
dotenv.config(); dotenv.config();
// Buat instance Axios // Buat instance Axios
const api = axios.create({ const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.example.com", // Ganti dengan URL API Anda baseURL: process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.example.com", // Ganti dengan URL API Anda
timeout: 10000, // Timeout dalam milidetik timeout: 60000, // Timeout dalam milidetik
withCredentials: true, // Kirim cookie otomatis dengan setiap permintaan withCredentials: true, // Kirim cookie otomatis dengan setiap permintaan
}); });
// Interceptor untuk menambahkan token dari cookie ke header Authorization (jika diperlukan) // Interceptor untuk menambahkan token dari cookie ke header Authorization (jika diperlukan)