|
| 1 | +/* eslint-disable @next/next/no-img-element */ |
| 2 | +"use client"; |
| 3 | + |
| 4 | +import { JsonDataType } from "@/type"; |
| 5 | +import { motion } from "framer-motion"; |
| 6 | +import { FormEvent } from "react"; |
| 7 | +import { AiOutlineLoading3Quarters } from "react-icons/ai"; |
| 8 | + |
| 9 | +type Props = { |
| 10 | + files: JsonDataType | null; |
| 11 | + fileName: string; |
| 12 | + isLoading: boolean; |
| 13 | + setFiles: (value: JsonDataType | null) => void; |
| 14 | + setFileName: (value: string) => void; |
| 15 | + handleProcess: (event: FormEvent) => void; |
| 16 | + handleChange: (event: React.ChangeEvent<HTMLInputElement>) => void; |
| 17 | +}; |
| 18 | + |
| 19 | +function Options({ |
| 20 | + files, |
| 21 | + fileName, |
| 22 | + isLoading, |
| 23 | + setFiles, |
| 24 | + setFileName, |
| 25 | + handleProcess, |
| 26 | + handleChange, |
| 27 | +}: Props) { |
| 28 | + return ( |
| 29 | + <div className="w-full p-10 bg-gradient-to-r from-gray-100 via-gray-200 to-gray-100 dark:bg-gradient-to-r dark:from-[#191a47] dark:via-[#0d0d37] dark:to-[#06375f] rounded-xl z-10"> |
| 30 | + <div className="text-center"> |
| 31 | + <h2 className="mt-5 text-3xl font-bold text-gray-900 dark:text-gray-100"> |
| 32 | + Config options |
| 33 | + </h2> |
| 34 | + <p className="mt-2 text-sm text-gray-400"> |
| 35 | + Enter the downloaded JSON text to restore |
| 36 | + </p> |
| 37 | + </div> |
| 38 | + <form className="mt-8 space-y-3" action="#" method="POST"> |
| 39 | + <div className="grid grid-cols-1 space-y-2"> |
| 40 | + <label className="text-sm font-bold text-gray-500 tracking-wide"> |
| 41 | + Attach Json Document |
| 42 | + </label> |
| 43 | + <div className="flex items-center justify-center w-full"> |
| 44 | + {files || fileName ? ( |
| 45 | + <div className="flex flex-col rounded-lg border-4 border-dashed w-full h-60 p-10 group text-center cursor-pointer overflow-hidden items-center"> |
| 46 | + <div |
| 47 | + onClick={() => { |
| 48 | + setFiles(null); |
| 49 | + setFileName(""); |
| 50 | + }} |
| 51 | + > |
| 52 | + {fileName.includes("json") ? ( |
| 53 | + <motion.img |
| 54 | + initial={{ opacity: 0, scale: 0.5 }} |
| 55 | + animate={{ opacity: 1, scale: 1 }} |
| 56 | + transition={{ |
| 57 | + duration: 0.8, |
| 58 | + delay: 0.5, |
| 59 | + ease: [0, 0.71, 0.2, 1.01], |
| 60 | + }} |
| 61 | + src="https://cdn2.iconfinder.com/data/icons/document-file-fill-outline-1/64/File_Document_Doc_Folder_JSON-512.png" |
| 62 | + alt="img" |
| 63 | + className="w-36 items-center" |
| 64 | + /> |
| 65 | + ) : ( |
| 66 | + <motion.img |
| 67 | + initial={{ opacity: 0, scale: 0.5 }} |
| 68 | + animate={{ opacity: 1, scale: 1 }} |
| 69 | + transition={{ |
| 70 | + duration: 0.8, |
| 71 | + delay: 0.5, |
| 72 | + ease: [0, 0.71, 0.2, 1.01], |
| 73 | + }} |
| 74 | + src="https://cdn3.iconfinder.com/data/icons/file-management/32/5_forbidden_ban_no_file_document-512.png" |
| 75 | + alt="img" |
| 76 | + className="w-36 items-center" |
| 77 | + /> |
| 78 | + )} |
| 79 | + <p>{fileName}</p> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + ) : ( |
| 83 | + <label className="flex flex-col rounded-lg border-4 border-dashed dark:border-gray-500 border-gray-300 w-full h-60 p-10 group text-center cursor-pointer"> |
| 84 | + <motion.div |
| 85 | + initial={{ opacity: 0, scale: 0.5 }} |
| 86 | + animate={{ opacity: 1, scale: 1 }} |
| 87 | + transition={{ |
| 88 | + duration: 0.8, |
| 89 | + delay: 0.5, |
| 90 | + ease: [0, 0.71, 0.2, 1.01], |
| 91 | + }} |
| 92 | + className="h-full w-full text-center flex flex-col justify-center items-center" |
| 93 | + > |
| 94 | + <div className="flex flex-auto max-h-48 w-2/5 -mt-10 justify-center"> |
| 95 | + <img |
| 96 | + className="has-mask h-36 object-center" |
| 97 | + src="https://cosmoindia.in/wp-content/uploads/2020/08/businessgrowth.png" |
| 98 | + alt="freepik image" |
| 99 | + /> |
| 100 | + </div> |
| 101 | + <p className="pointer-none text-gray-500 "> |
| 102 | + <span className="text-sm">Drag and drop</span> files here{" "} |
| 103 | + <br /> or{" "} |
| 104 | + <span id="" className="text-blue-600 hover:underline"> |
| 105 | + select a file |
| 106 | + </span>{" "} |
| 107 | + from your computer |
| 108 | + </p> |
| 109 | + </motion.div> |
| 110 | + <input type="file" className="hidden" onChange={handleChange} /> |
| 111 | + </label> |
| 112 | + )} |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + <p className="text-sm text-gray-700 dark:text-gray-300"> |
| 116 | + <span>File type: json</span> |
| 117 | + </p> |
| 118 | + <div> |
| 119 | + <button |
| 120 | + onClick={handleProcess} |
| 121 | + className="my-5 w-full flex justify-center bg-blue-500 text-gray-100 p-4 rounded-full tracking-wide font-semibold focus:outline-none focus:shadow-outline hover:bg-blue-600 cursor-pointer transition ease-in duration-300" |
| 122 | + > |
| 123 | + {isLoading ? ( |
| 124 | + <AiOutlineLoading3Quarters size={25} className="animate-spin" /> |
| 125 | + ) : ( |
| 126 | + "Process" |
| 127 | + )} |
| 128 | + </button> |
| 129 | + </div> |
| 130 | + </form> |
| 131 | + </div> |
| 132 | + ); |
| 133 | +} |
| 134 | + |
| 135 | +export default Options; |
0 commit comments