File size: 1,323 Bytes
3b6afc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React from 'react';
import FileUpload from '../NewConversationMenu/FileUpload';

const GoogleConfig = ({ setToken }: { setToken: React.Dispatch<React.SetStateAction<string>> }) => {
  return (
    <FileUpload
      id="googleKey"
      className="w-full"
      text="Import Service Account JSON Key"
      successText="Successfully Imported Service Account JSON Key"
      invalidText="Invalid Service Account JSON Key, Did you import the correct file?"
      validator={(credentials) => {
        if (!credentials) {
          return false;
        }

        if (
          !credentials.client_email ||
          typeof credentials.client_email !== 'string' ||
          credentials.client_email.length <= 2
        ) {
          return false;
        }

        if (
          !credentials.project_id ||
          typeof credentials.project_id !== 'string' ||
          credentials.project_id.length <= 2
        ) {
          return false;
        }

        if (
          !credentials.private_key ||
          typeof credentials.private_key !== 'string' ||
          credentials.private_key.length <= 600
        ) {
          return false;
        }

        return true;
      }}
      onFileSelected={(data) => {
        setToken(JSON.stringify(data));
      }}
    />
  );
};

export default GoogleConfig;