|
| 1 | +import { useState } from "react"; |
| 2 | +import { toast } from "react-toastify"; |
| 3 | + |
| 4 | +import { Button } from "@Components/RadixComponents/Button"; |
| 5 | +import { FormControl, Input, Label } from "@Components/common/FormUI"; |
| 6 | +import { createProjectFromImageryExif } from "@Services/classification"; |
| 7 | +import hasErrorBoundary from "@Utils/hasErrorBoundary"; |
| 8 | + |
| 9 | +const Import = () => { |
| 10 | + const [endpoint, setEndpoint] = useState("s3.amazonaws.com"); |
| 11 | + const [bucketName, setBucketName] = useState(""); |
| 12 | + const [path, setPath] = useState(""); |
| 13 | + const [projectName, setProjectName] = useState(""); |
| 14 | + const [submitting, setSubmitting] = useState(false); |
| 15 | + const [submitted, setSubmitted] = useState(false); |
| 16 | + |
| 17 | + const handleSubmit = async (e: React.FormEvent) => { |
| 18 | + e.preventDefault(); |
| 19 | + if (!endpoint || !bucketName || !projectName) { |
| 20 | + toast.error("Endpoint, bucket name, and project name are required"); |
| 21 | + return; |
| 22 | + } |
| 23 | + setSubmitting(true); |
| 24 | + try { |
| 25 | + await createProjectFromImageryExif({ |
| 26 | + endpoint, |
| 27 | + bucket_name: bucketName, |
| 28 | + path, |
| 29 | + project_name: projectName, |
| 30 | + }); |
| 31 | + setSubmitted(true); |
| 32 | + toast.success("Project creation job submitted"); |
| 33 | + } catch (err: any) { |
| 34 | + const detail = err?.response?.data?.detail || err?.message || "Request failed"; |
| 35 | + toast.error(detail); |
| 36 | + } finally { |
| 37 | + setSubmitting(false); |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + return ( |
| 42 | + <section className="naxatw-flex naxatw-min-h-screen-nav naxatw-flex-col naxatw-items-center naxatw-px-4 naxatw-py-8 md:naxatw-px-16"> |
| 43 | + <div className="naxatw-w-full naxatw-max-w-2xl naxatw-rounded-md naxatw-bg-white naxatw-p-6 naxatw-shadow-md"> |
| 44 | + <h4 className="naxatw-mb-2 naxatw-font-bold">Import imagery from S3</h4> |
| 45 | + <p className="naxatw-mb-6 naxatw-text-body-md naxatw-text-grey-600"> |
| 46 | + Point at a public S3-compatible bucket. We'll scan EXIF GPS from each JPEG |
| 47 | + (subdirectories up to 3 levels deep), build a buffered AOI, and create a drone-tm project. |
| 48 | + Imagery transfer and ingestion are run separately afterwards. |
| 49 | + </p> |
| 50 | + |
| 51 | + <form onSubmit={handleSubmit} className="naxatw-flex naxatw-flex-col naxatw-gap-4"> |
| 52 | + <FormControl> |
| 53 | + <Label>Project name</Label> |
| 54 | + <Input |
| 55 | + placeholder="My drone survey" |
| 56 | + value={projectName} |
| 57 | + onChange={(e) => setProjectName(e.target.value)} |
| 58 | + disabled={submitting} |
| 59 | + required |
| 60 | + /> |
| 61 | + </FormControl> |
| 62 | + |
| 63 | + <FormControl> |
| 64 | + <Label>S3 endpoint</Label> |
| 65 | + <Input |
| 66 | + placeholder="s3.amazonaws.com" |
| 67 | + value={endpoint} |
| 68 | + onChange={(e) => setEndpoint(e.target.value)} |
| 69 | + disabled={submitting} |
| 70 | + required |
| 71 | + /> |
| 72 | + </FormControl> |
| 73 | + |
| 74 | + <FormControl> |
| 75 | + <Label>Bucket name</Label> |
| 76 | + <Input |
| 77 | + placeholder="my-bucket" |
| 78 | + value={bucketName} |
| 79 | + onChange={(e) => setBucketName(e.target.value)} |
| 80 | + disabled={submitting} |
| 81 | + required |
| 82 | + /> |
| 83 | + </FormControl> |
| 84 | + |
| 85 | + <FormControl> |
| 86 | + <Label>Path / prefix (optional)</Label> |
| 87 | + <Input |
| 88 | + placeholder="surveys/2025-01/site-a" |
| 89 | + value={path} |
| 90 | + onChange={(e) => setPath(e.target.value)} |
| 91 | + disabled={submitting} |
| 92 | + /> |
| 93 | + </FormControl> |
| 94 | + |
| 95 | + <Button |
| 96 | + className="naxatw-bg-red naxatw-mt-2 naxatw-self-end" |
| 97 | + type="submit" |
| 98 | + disabled={submitting || !endpoint || !bucketName || !projectName} |
| 99 | + withLoader |
| 100 | + isLoading={submitting} |
| 101 | + > |
| 102 | + Create project |
| 103 | + </Button> |
| 104 | + </form> |
| 105 | + |
| 106 | + {submitted && ( |
| 107 | + <div className="naxatw-mt-6 naxatw-rounded-md naxatw-border naxatw-border-grey-200 naxatw-bg-grey-50 naxatw-p-4 naxatw-text-body-md"> |
| 108 | + Please be patient while the project is created in the background. For many images, this |
| 109 | + may take several hours. The new project will appear on your projects list once it has |
| 110 | + been created. |
| 111 | + </div> |
| 112 | + )} |
| 113 | + </div> |
| 114 | + </section> |
| 115 | + ); |
| 116 | +}; |
| 117 | + |
| 118 | +export default hasErrorBoundary(Import); |
0 commit comments