remove wagtail and admin website, remove edit option, from hitung ayam, add create flock to settings
This commit is contained in:
1 parent
74dd3faf60
commit
30a736641f
39 files changed
+634
-819
No files matched your search
+26
-1
@@ -1,11 +1,12 @@
|
||||
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { api, errorMessage } from '../services/apiClient.ts';
|
||||
import type { Cycle, Kandang, Site } from '../types/api.ts';
|
||||
import type { Cycle, Flock, Kandang, Site } from '../types/api.ts';
|
||||
import { useAuth } from './AuthContext.tsx';
|
||||
|
||||
type FarmContextValue = {
|
||||
sites: Site[];
|
||||
kandangs: Kandang[];
|
||||
flocks: Flock[];
|
||||
cycles: Cycle[];
|
||||
selectedSiteId: number | null;
|
||||
selectedKandangId: number | null;
|
||||
@@ -27,6 +28,7 @@ export const FarmProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
const { user } = useAuth();
|
||||
const [sites, setSites] = useState<Site[]>([]);
|
||||
const [kandangs, setKandangs] = useState<Kandang[]>([]);
|
||||
const [flocks, setFlocks] = useState<Flock[]>([]);
|
||||
const [cycles, setCycles] = useState<Cycle[]>([]);
|
||||
const [selectedSiteId, setSelectedSiteId] = useState<number | null>(null);
|
||||
const [selectedKandangId, setSelectedKandangId] = useState<number | null>(null);
|
||||
@@ -43,6 +45,7 @@ export const FarmProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
if (!user) {
|
||||
setSites([]);
|
||||
setKandangs([]);
|
||||
setFlocks([]);
|
||||
setCycles([]);
|
||||
return;
|
||||
}
|
||||
@@ -94,6 +97,26 @@ export const FarmProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
};
|
||||
}, [user, selectedSiteId, reloadToken]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!user || selectedKandangId == null) {
|
||||
setFlocks([]);
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
try {
|
||||
const next = await api.flocks.list({ kandang_id: selectedKandangId });
|
||||
if (cancelled) return;
|
||||
setFlocks(next);
|
||||
} catch (err) {
|
||||
if (!cancelled) setError(errorMessage(err));
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [user, selectedKandangId, reloadToken]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!user || selectedKandangId == null) {
|
||||
setCycles([]);
|
||||
@@ -138,6 +161,7 @@ export const FarmProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
() => ({
|
||||
sites,
|
||||
kandangs,
|
||||
flocks,
|
||||
cycles,
|
||||
selectedSiteId,
|
||||
selectedKandangId,
|
||||
@@ -155,6 +179,7 @@ export const FarmProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
[
|
||||
sites,
|
||||
kandangs,
|
||||
flocks,
|
||||
cycles,
|
||||
selectedSiteId,
|
||||
selectedKandangId,
|
||||
|
||||
Reference in new issue
Block a user