87 lines
3.0 KiB
TypeScript
87 lines
3.0 KiB
TypeScript
import React, { FC } from "react";
|
||
import { Text } from "react-native";
|
||
import { Dialog, Input, Button } from "react-native-elements";
|
||
import { trainDataType } from "../../../lib/trainPositionTextArray";
|
||
import { getStationID } from "@/lib/eachTrainInfoCoreLib/getStationData";
|
||
import { useStationList } from "@/stateBox/useStationList";
|
||
type Props = {
|
||
dialog: boolean;
|
||
setDialog: (dialog: boolean) => void;
|
||
currentTrainData: trainDataType;
|
||
stationNumberInput: string;
|
||
posInput: string;
|
||
descInput: string;
|
||
lineInput: string;
|
||
setPosInput: (pos: string) => void;
|
||
setDescInput: (desc: string) => void;
|
||
setLineInput: (line: string) => void;
|
||
|
||
};
|
||
export const TrainPositionDataPush: FC<Props> = ({
|
||
dialog,
|
||
setDialog,
|
||
currentTrainData,
|
||
stationNumberInput,
|
||
lineInput,
|
||
setLineInput,
|
||
posInput,
|
||
setPosInput,
|
||
descInput,
|
||
setDescInput,
|
||
}) => {
|
||
const { stationList } = useStationList();
|
||
const sendPlatformData = () => {
|
||
fetch(`https://n8n.haruk.in/webhook/JR-shikoku-PosID-v3`, {
|
||
method: "POST",
|
||
headers: { "Content-Type": "application/json" },
|
||
body: JSON.stringify({
|
||
PosId: currentTrainData?.PosNum, //自動:位置情報ID
|
||
StationId: getStationID(currentTrainData?.Pos, stationList), //自動:駅ID
|
||
StationName: currentTrainData?.Pos, //自動:駅名、漢字
|
||
lineName: currentTrainData?.Line, //自動:位置情報路線ID(koutoku/yosan)
|
||
Description: descInput, //手動入力、参考情報
|
||
platformNumber: parseInt(posInput), //手動入力、乗り場表記
|
||
lineNumber: parseInt(lineInput), //手動入力、番線表記
|
||
}),
|
||
})
|
||
.then(() => {
|
||
alert("位置情報データを送信しました。");
|
||
setDialog(false);
|
||
setPosInput("");
|
||
setDescInput("");
|
||
})
|
||
.catch(() => {
|
||
alert("位置情報データの送信に失敗しました。");
|
||
});
|
||
};
|
||
return (
|
||
<Dialog isVisible={dialog} onBackdropPress={() => setDialog(false)}>
|
||
<Text style={{ fontSize: 20, fontWeight: "bold" }}>駅番線情報投稿機能</Text>
|
||
<Text>路線: {currentTrainData?.Line}</Text>
|
||
<Text>地点ID: {currentTrainData?.PosNum}</Text>
|
||
<Text>駅名: {currentTrainData?.Pos}</Text>
|
||
<Text>駅ナンバー: {stationNumberInput}</Text>
|
||
<Input
|
||
label="乗り場"
|
||
inputMode="numeric"
|
||
value={posInput}
|
||
onChangeText={setPosInput}
|
||
/>
|
||
<Input
|
||
label="番線"
|
||
inputMode="numeric"
|
||
value={lineInput}
|
||
onChangeText={setLineInput}
|
||
/>
|
||
<Input
|
||
label="参考情報"
|
||
inputMode="text"
|
||
value={descInput}
|
||
onChangeText={setDescInput}
|
||
/>
|
||
<Text style={{ fontSize: 12, fontWeight: "bold" }}>この機能は駅の停車位置に関する情報を投稿する機能です。列車の遅れ、運行情報を投稿するフォームではありませんのでご注意ください。</Text>
|
||
<Button title="送信" onPress={sendPlatformData} />
|
||
</Dialog>
|
||
);
|
||
};
|