feat: role system
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
stationsStore,
|
||||
languageStore,
|
||||
cityStore,
|
||||
authStore,
|
||||
mediaStore,
|
||||
isMediaIdEmpty,
|
||||
useSelectedCity,
|
||||
@@ -39,7 +40,8 @@ export const StationCreatePage = observer(() => {
|
||||
createStation,
|
||||
setLanguageCreateStationData,
|
||||
} = stationsStore;
|
||||
const { cities, getCities } = cityStore;
|
||||
const { getCities } = cityStore;
|
||||
const canReadCities = authStore.canRead("cities");
|
||||
const { selectedCityId, selectedCity } = useSelectedCity();
|
||||
const [coordinates, setCoordinates] = useState<string>("");
|
||||
const [isSelectMediaOpen, setIsSelectMediaOpen] = useState(false);
|
||||
@@ -104,15 +106,35 @@ export const StationCreatePage = observer(() => {
|
||||
|
||||
useEffect(() => {
|
||||
const fetchCities = async () => {
|
||||
await getCities("ru");
|
||||
await getCities("en");
|
||||
await getCities("zh");
|
||||
if (!authStore.me) {
|
||||
await authStore.getMeAction().catch(() => undefined);
|
||||
}
|
||||
if (authStore.canRead("cities")) {
|
||||
await getCities("ru");
|
||||
return;
|
||||
}
|
||||
await authStore.fetchMeCities().catch(() => undefined);
|
||||
};
|
||||
|
||||
fetchCities();
|
||||
mediaStore.getMedia();
|
||||
}, []);
|
||||
|
||||
const baseCities = canReadCities
|
||||
? cityStore.cities["ru"].data
|
||||
: authStore.meCities["ru"].map((city) => ({
|
||||
id: city.city_id,
|
||||
name: city.name,
|
||||
country: "",
|
||||
country_code: "",
|
||||
arms: "",
|
||||
}));
|
||||
|
||||
const availableCities =
|
||||
selectedCity?.id && !baseCities.some((city) => city.id === selectedCity.id)
|
||||
? [selectedCity, ...baseCities]
|
||||
: baseCities;
|
||||
|
||||
const handleMediaSelect = (media: {
|
||||
id: string;
|
||||
filename: string;
|
||||
@@ -229,7 +251,7 @@ export const StationCreatePage = observer(() => {
|
||||
value={createStationData.common.city_id || ""}
|
||||
label="Город"
|
||||
onChange={(e) => {
|
||||
const selectedCity = cities["ru"].data.find(
|
||||
const selectedCity = availableCities.find(
|
||||
(city) => city.id === e.target.value
|
||||
);
|
||||
setCreateCommonData({
|
||||
@@ -238,7 +260,7 @@ export const StationCreatePage = observer(() => {
|
||||
});
|
||||
}}
|
||||
>
|
||||
{cities["ru"].data.map((city) => (
|
||||
{availableCities.map((city) => (
|
||||
<MenuItem key={city.id} value={city.id}>
|
||||
{city.name}
|
||||
</MenuItem>
|
||||
|
||||
Reference in New Issue
Block a user