feat: Add more pages
This commit is contained in:
76
src/shared/store/CarrierStore/index.tsx
Normal file
76
src/shared/store/CarrierStore/index.tsx
Normal file
@ -0,0 +1,76 @@
|
||||
import { authInstance } from "@shared";
|
||||
import { makeAutoObservable, runInAction } from "mobx";
|
||||
|
||||
export type Carrier = {
|
||||
id: number;
|
||||
short_name: string;
|
||||
full_name: string;
|
||||
slogan: string;
|
||||
city: string;
|
||||
city_id: number;
|
||||
logo: string;
|
||||
main_color: string;
|
||||
left_color: string;
|
||||
right_color: string;
|
||||
};
|
||||
|
||||
class CarrierStore {
|
||||
carriers: Carrier[] = [];
|
||||
carrier: Carrier | null = null;
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
getCarriers = async () => {
|
||||
const response = await authInstance.get("/carrier");
|
||||
|
||||
runInAction(() => {
|
||||
this.carriers = response.data;
|
||||
});
|
||||
};
|
||||
|
||||
deleteCarrier = async (id: number) => {
|
||||
await authInstance.delete(`/carrier/${id}`);
|
||||
|
||||
runInAction(() => {
|
||||
this.carriers = this.carriers.filter((carrier) => carrier.id !== id);
|
||||
});
|
||||
};
|
||||
|
||||
getCarrier = async (id: number) => {
|
||||
const response = await authInstance.get(`/carrier/${id}`);
|
||||
runInAction(() => {
|
||||
this.carrier = response.data;
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
createCarrier = async (
|
||||
fullName: string,
|
||||
shortName: string,
|
||||
city: string,
|
||||
cityId: number,
|
||||
primaryColor: string,
|
||||
secondaryColor: string,
|
||||
accentColor: string,
|
||||
slogan: string,
|
||||
logoId: string
|
||||
) => {
|
||||
const response = await authInstance.post("/carrier", {
|
||||
full_name: fullName,
|
||||
short_name: shortName,
|
||||
city,
|
||||
city_id: cityId,
|
||||
primary_color: primaryColor,
|
||||
secondary_color: secondaryColor,
|
||||
accent_color: accentColor,
|
||||
slogan,
|
||||
logo: logoId,
|
||||
});
|
||||
runInAction(() => {
|
||||
this.carriers.push(response.data);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const carrierStore = new CarrierStore();
|
Reference in New Issue
Block a user