more fixes
This commit is contained in:
@ -20,6 +20,9 @@ import { LanguageSwitch } from "../../LanguageSwitch/index";
|
||||
|
||||
import { useState } from "react";
|
||||
import { stationStore } from "../../../store/StationStore";
|
||||
import { useCustom } from "@refinedev/core";
|
||||
import { useApiUrl } from "@refinedev/core";
|
||||
import { StationItem } from "src/pages/route/types";
|
||||
const MemoizedSimpleMDE = memo(MarkdownEditor);
|
||||
|
||||
const TRANSFER_FIELDS = [
|
||||
@ -47,7 +50,7 @@ const style = {
|
||||
};
|
||||
|
||||
export const StationEditModal = observer(() => {
|
||||
const { stationModalOpen, setStationModalOpenAction, selectedStationId } =
|
||||
const { stationModalOpen, setStationModalOpenAction, selectedStationId, selectedRouteId } =
|
||||
stationStore;
|
||||
const { language } = languageStore;
|
||||
|
||||
@ -57,6 +60,14 @@ export const StationEditModal = observer(() => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const apiUrl = useApiUrl();
|
||||
|
||||
const { data: stationQuery, isLoading: isStationLoading } = useCustom({
|
||||
url: `${apiUrl}/route/${selectedRouteId ?? 1}/station`,
|
||||
method: 'get'
|
||||
});
|
||||
|
||||
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
@ -65,14 +76,15 @@ export const StationEditModal = observer(() => {
|
||||
reset,
|
||||
setValue,
|
||||
watch,
|
||||
handleSubmit,
|
||||
} = useForm({
|
||||
refineCoreProps: {
|
||||
resource: "station",
|
||||
id: selectedStationId ?? undefined,
|
||||
resource: `route/${selectedRouteId ?? 1}/station`,
|
||||
action: "edit",
|
||||
id: "",
|
||||
redirect: false,
|
||||
|
||||
onMutationSuccess: () => {
|
||||
onMutationSuccess: (data) => {
|
||||
console.log(data);
|
||||
setStationModalOpenAction(false);
|
||||
reset();
|
||||
window.location.reload();
|
||||
@ -85,6 +97,19 @@ export const StationEditModal = observer(() => {
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (stationModalOpen) {
|
||||
const station = stationQuery?.data?.find((station: StationItem) => station.id === selectedStationId);
|
||||
if(!station) return;
|
||||
for(const key in station) {
|
||||
setValue(key, station[key]);
|
||||
console.log(key, station[key]);
|
||||
}
|
||||
setValue("station_id", station.id);
|
||||
console.log(stationQuery);
|
||||
}
|
||||
}, [stationModalOpen, stationQuery]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={stationModalOpen}
|
||||
|
Reference in New Issue
Block a user