feat: add Ina Trading portal flows and API integration

This commit is contained in:
Wira Basalamah
2026-04-24 05:19:05 +07:00
parent d98b4769f0
commit e08f2f9286
97 changed files with 18889 additions and 110 deletions

View File

@ -0,0 +1,78 @@
"use client";
import { useParams } from "next/navigation";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { WarehouseForm, WarehouseFormState } from "../../WarehouseForm";
function getCachedWarehouse(warehouseId: string): WarehouseFormState | null {
if (typeof window === "undefined" || !warehouseId) return null;
const cached = sessionStorage.getItem("editWarehouseCache");
if (!cached) return null;
try {
const raw = JSON.parse(cached) as Record<string, unknown>;
if (raw.id !== warehouseId) return null;
sessionStorage.removeItem("editWarehouseCache");
return {
name: typeof raw.name === "string" ? raw.name : "",
address: typeof raw.address === "string" ? raw.address : "",
country: typeof raw.country === "string" ? raw.country : "Indonesia",
province: typeof raw.province === "string" ? raw.province : "",
provinceId: "",
city: typeof raw.city === "string" ? raw.city : "",
cityId: "",
postalCode: typeof raw.postalCode === "string" ? raw.postalCode : "",
latitude: raw.latitude != null ? String(raw.latitude) : "",
longitude: raw.longitude != null ? String(raw.longitude) : "",
warehouseType:
typeof raw.warehouseType === "string" ? raw.warehouseType : "INA",
};
} catch {
return null;
}
}
export default function EditWarehousePage() {
const params = useParams<{ warehouseId: string }>();
const router = useRouter();
const [initialData] = useState<WarehouseFormState | null>(() =>
getCachedWarehouse(params.warehouseId)
);
const loadError = initialData
? ""
: "Data tidak tersedia. Kembali ke daftar warehouse dan klik Edit lagi.";
if (loadError) {
return (
<div className="p-8 flex flex-col items-center justify-center h-64 gap-4">
<span className="material-symbols-outlined text-4xl text-error">error</span>
<p className="text-sm font-semibold text-error">{loadError}</p>
<button onClick={() => router.back()} className="text-sm font-bold text-primary hover:underline">Kembali</button>
</div>
);
}
if (!initialData) {
return (
<div className="p-8 flex items-center justify-center h-64">
<span className="material-symbols-outlined text-4xl text-slate-300 animate-spin">progress_activity</span>
</div>
);
}
return (
<WarehouseForm
initialData={initialData}
pageTitle="Edit Warehouse"
pageSubtitle="Perbarui informasi gudang"
submitLabel="Simpan Perubahan"
submittingLabel="Menyimpan..."
successMessage="Warehouse berhasil diperbarui! Mengalihkan..."
apiMethod="PUT"
apiUrl={`/api/warehouses/${params.warehouseId}`}
/>
);
}