feat: Add more pages
This commit is contained in:
49
src/shared/store/CountryStore/index.ts
Normal file
49
src/shared/store/CountryStore/index.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
export type Country = {
|
||||
code: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
class CountryStore {
|
||||
countries: Country[] = [];
|
||||
country: Country | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getCountries = async () => {
|
||||
const response = await authInstance.get("/country");
|
||||
|
||||
runInAction(() => {
|
||||
this.countries = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
getCountry = async (code: string) => {
|
||||
const response = await authInstance.get(`/country/${code}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.country = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteCountry = async (code: string) => {
|
||||
await authInstance.delete(`/country/${code}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.countries = this.countries.filter(
|
||||
(country) => country.code !== code
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
createCountry = async (code: string, name: string) => {
|
||||
await authInstance.post("/country", { code: code, name: name });
|
||||
await this.getCountries();
|
||||
};
|
||||
}
|
||||
|
||||
export const countryStore = new CountryStore();
|
Reference in New Issue
Block a user