adjust registered by to managed by on db aslo remove url and api key on adding sites for gm
This commit is contained in:
1 parent
64b37b6b6d
commit
521f36d22d
15 files changed
+112
-75
No files matched your search
@@ -68,10 +68,10 @@ const BuhViewList: React.FC = () => {
|
||||
const sitesByGm = useMemo(() => {
|
||||
const map = new Map<number, ActiveSite[]>();
|
||||
for (const site of activeSites) {
|
||||
if (site.registered_by == null) continue;
|
||||
const rows = map.get(site.registered_by) ?? [];
|
||||
if (site.managed_by == null) continue;
|
||||
const rows = map.get(site.managed_by) ?? [];
|
||||
rows.push(site);
|
||||
map.set(site.registered_by, rows);
|
||||
map.set(site.managed_by, rows);
|
||||
}
|
||||
return map;
|
||||
}, [activeSites]);
|
||||
@@ -224,8 +224,6 @@ const GmViewList: React.FC = () => {
|
||||
const [name, setName] = useState('');
|
||||
const [code, setCode] = useState('');
|
||||
const [codeTouched, setCodeTouched] = useState(false);
|
||||
const [apiBaseUrl, setApiBaseUrl] = useState('');
|
||||
const [apiKey, setApiKey] = useState('');
|
||||
|
||||
const flash = (msg: string) => {
|
||||
setNotice(msg);
|
||||
@@ -263,8 +261,6 @@ const GmViewList: React.FC = () => {
|
||||
setName('');
|
||||
setCode('');
|
||||
setCodeTouched(false);
|
||||
setApiBaseUrl('');
|
||||
setApiKey('');
|
||||
};
|
||||
|
||||
const wrap = async (fn: () => Promise<void>) => {
|
||||
@@ -314,7 +310,7 @@ const GmViewList: React.FC = () => {
|
||||
<div>
|
||||
<PageHeader
|
||||
title="Pengaturan"
|
||||
subtitle="Pilih BUH Anda, lalu daftarkan site ke daftar tampilan"
|
||||
subtitle="Pilih BUH Anda, lalu daftarkan site dengan nama dan kode"
|
||||
/>
|
||||
{error && (
|
||||
<div className="mb-4">
|
||||
@@ -400,7 +396,8 @@ const GmViewList: React.FC = () => {
|
||||
<section className="bg-white rounded-xl shadow-sm p-5">
|
||||
<h2 className="font-semibold text-gray-800 mb-1">Tambah site</h2>
|
||||
<p className="text-xs text-gray-500 mb-4">
|
||||
Daftarkan URL API dasbor kota agar data site muncul di daftar tampilan Anda.
|
||||
Masukkan nama dan kode yang sama dengan yang diisi manajer di dasbor site, agar site
|
||||
terhubung ke daftar tampilan Anda.
|
||||
</p>
|
||||
<form
|
||||
className="space-y-3"
|
||||
@@ -412,8 +409,6 @@ const GmViewList: React.FC = () => {
|
||||
const created = await api.activeSites.create({
|
||||
code: resolvedCode,
|
||||
name: name.trim(),
|
||||
api_base_url: apiBaseUrl.trim(),
|
||||
...(apiKey.trim() ? { api_key: apiKey.trim() } : {}),
|
||||
is_active: true,
|
||||
});
|
||||
resetForm();
|
||||
@@ -448,28 +443,6 @@ const GmViewList: React.FC = () => {
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label className="block text-sm text-gray-700">
|
||||
URL API kota
|
||||
<input
|
||||
className={`${inputClass} mt-1`}
|
||||
type="url"
|
||||
placeholder="https://site.example/api/v1"
|
||||
value={apiBaseUrl}
|
||||
onChange={(e) => setApiBaseUrl(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label className="block text-sm text-gray-700">
|
||||
API key (opsional)
|
||||
<input
|
||||
className={`${inputClass} mt-1`}
|
||||
type="password"
|
||||
autoComplete="off"
|
||||
placeholder="X-API-Key untuk sinkron dari kota"
|
||||
value={apiKey}
|
||||
onChange={(e) => setApiKey(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-red-600 text-white px-4 py-2 rounded-lg text-sm font-semibold disabled:opacity-50"
|
||||
@@ -496,7 +469,6 @@ const GmViewList: React.FC = () => {
|
||||
<div className="min-w-0">
|
||||
<p className="text-sm font-semibold text-gray-800 truncate">{site.name}</p>
|
||||
<p className="text-xs text-gray-500 truncate">{site.code}</p>
|
||||
<p className="text-xs text-gray-400 truncate mt-0.5">{site.api_base_url}</p>
|
||||
<p className="text-xs mt-1">
|
||||
<span
|
||||
className={
|
||||
@@ -507,7 +479,6 @@ const GmViewList: React.FC = () => {
|
||||
>
|
||||
{site.is_active ? 'Aktif' : 'Nonaktif'}
|
||||
</span>
|
||||
{site.has_api_key ? ' · API key tersimpan' : ''}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
|
||||
@@ -103,8 +103,8 @@ describe('SettingsPage city site registry', () => {
|
||||
name: 'Sukawarna',
|
||||
api_base_url: 'https://sukawarna.example/api/v1',
|
||||
has_api_key: true,
|
||||
registered_by: 5,
|
||||
registered_by_name: 'gm.user',
|
||||
managed_by: 5,
|
||||
managed_by_name: 'gm.user',
|
||||
is_active: true,
|
||||
last_synced_at: null,
|
||||
last_sync_status: '',
|
||||
@@ -119,8 +119,8 @@ describe('SettingsPage city site registry', () => {
|
||||
name: 'Cikupa',
|
||||
api_base_url: 'https://cikupa.example/api/v1',
|
||||
has_api_key: false,
|
||||
registered_by: 5,
|
||||
registered_by_name: 'gm.user',
|
||||
managed_by: 5,
|
||||
managed_by_name: 'gm.user',
|
||||
is_active: true,
|
||||
last_synced_at: null,
|
||||
last_sync_status: '',
|
||||
@@ -159,16 +159,12 @@ describe('SettingsPage city site registry', () => {
|
||||
fireEvent.change(screen.getByPlaceholderText('Contoh: Sukawarna'), {
|
||||
target: { value: 'Cikupa' },
|
||||
});
|
||||
fireEvent.change(screen.getByPlaceholderText('https://site.example/api/v1'), {
|
||||
target: { value: 'https://cikupa.example/api/v1' },
|
||||
});
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Tambah ke daftar' }));
|
||||
|
||||
await waitFor(() => expect(createMock).toHaveBeenCalledTimes(1));
|
||||
expect(createMock).toHaveBeenCalledWith({
|
||||
code: 'cikupa',
|
||||
name: 'Cikupa',
|
||||
api_base_url: 'https://cikupa.example/api/v1',
|
||||
is_active: true,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user