feat: Add more pages
This commit is contained in:
@ -11,19 +11,53 @@ type City = {
|
||||
|
||||
class CityStore {
|
||||
cities: City[] = [];
|
||||
|
||||
city: City | null = null;
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getCities = async () => {
|
||||
if (this.cities.length !== 0) return;
|
||||
|
||||
const response = await authInstance.get("/city");
|
||||
|
||||
runInAction(() => {
|
||||
this.cities = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteCity = async (id: number) => {
|
||||
await authInstance.delete(`/city/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.cities = this.cities.filter((city) => city.id !== id);
|
||||
});
|
||||
};
|
||||
|
||||
getCity = async (id: string) => {
|
||||
const response = await authInstance.get(`/city/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.city = response.data;
|
||||
});
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
createCity = async (
|
||||
name: string,
|
||||
country: string,
|
||||
countryCode: string,
|
||||
mediaId: string
|
||||
) => {
|
||||
const response = await authInstance.post("/city", {
|
||||
name: name,
|
||||
country: country,
|
||||
country_code: countryCode,
|
||||
arms: mediaId,
|
||||
});
|
||||
runInAction(() => {
|
||||
this.cities.push(response.data);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const cityStore = new CityStore();
|
||||
|
Reference in New Issue
Block a user