import React, { useContext, useState } from "react"; import { NotificationContext } from "context/notification"; import scriptAPI from "services/entities/scripts"; import Button from "components/buttons/Button"; import Modal from "components/Modal"; import { getErrorMessage } from "./helpers"; import ScriptUploader from "../ScriptUploader"; const baseClass = "script-upload-modal"; interface IScriptUploadModal { onExit: () => void; onSubmit: () => void; currentTeamId: number; } const ScriptUploadModal = ({ onSubmit, onExit, currentTeamId, }: IScriptUploadModal) => { const { renderFlash } = useContext(NotificationContext); const [selectedFile, setSelectedFile] = useState(null); const [showLoading, setShowLoading] = useState(false); const onUploadFile = async () => { if (!selectedFile) { return; } setShowLoading(true); try { await scriptAPI.uploadScript(selectedFile, currentTeamId); renderFlash("success", "Successfully uploaded!"); onSubmit(); } catch (e) { renderFlash("error", getErrorMessage(e)); } finally { setShowLoading(false); } }; const additionalInfo = selectedFile && selectedFile.name.match(/\.sh$/) ? 'On macOS and Linux, script will run according to the interpreter specified in the first line: "#!/bin/sh", "#!/bin/zsh", or "#!/bin/bash"' : undefined; return ( <>
setSelectedFile(file)} selectedFile={selectedFile} forModal />
{additionalInfo && (

{additionalInfo}

)}
); }; export default ScriptUploadModal;