(event: React.FormEvent)
| 158 | }; |
| 159 | |
| 160 | const handleSubmit = async (event: React.FormEvent) => { |
| 161 | event.preventDefault(); |
| 162 | |
| 163 | try { |
| 164 | // Validate input syntax |
| 165 | if (!isHumanToSql) { |
| 166 | const pattern = |
| 167 | /^\s*(select|insert|update|delete|create|alter|drop|truncate|grant|revoke|use|begin|commit|rollback)\s/i; |
| 168 | const regex = new RegExp(pattern); |
| 169 | if (!regex.test(inputText)) { |
| 170 | toast.error("Invalid SQL syntax."); |
| 171 | return; |
| 172 | } |
| 173 | } |
| 174 | if (showTableSchema && !isValidTableSchema(tableSchema)) { |
| 175 | toast.error("Invalid table schema."); |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | translate({ inputText, tableSchema, isHumanToSql }); |
| 180 | setHasTranslated(true); |
| 181 | } catch (error) { |
| 182 | console.log(error); |
| 183 | toast.error(`Error translating ${isHumanToSql ? "to SQL" : "to human"}.`); |
| 184 | } |
| 185 | }; |
| 186 | |
| 187 | return ( |
| 188 | <div className="flex flex-col items-center justify-center min-h-screen"> |
no test coverage detected