Files
parcer/src/components/molecules/IntegrationSettings.tsx

93 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-09-17 17:28:43 +05:30
import React, { useState } from 'react';
import { GenericModal } from "../atoms/GenericModal";
import { MenuItem, TextField, Typography } from "@mui/material";
import Button from "@mui/material/Button";
import { modalStyle } from "./AddWhereCondModal";
2024-09-17 20:16:50 +05:30
interface IntegrationProps {
2024-09-17 17:28:43 +05:30
isOpen: boolean;
2024-09-17 20:16:50 +05:30
handleSubmit: (data: IntegrationSettings) => void;
2024-09-17 17:28:43 +05:30
handleClose: () => void;
}
2024-09-17 20:16:50 +05:30
export interface IntegrationSettings {
2024-09-17 20:10:51 +05:30
credentials: string;
spreadsheetId: string;
range: string;
data: string;
2024-09-17 17:28:43 +05:30
}
2024-09-17 20:20:07 +05:30
export const IntegrationSettingsModal = ({ isOpen, handleSubmit, handleClose }: IntegrationProps) => {
2024-09-17 17:28:43 +05:30
2024-09-17 20:16:50 +05:30
const [settings, setSettings] = useState<IntegrationSettings>({
2024-09-17 20:10:51 +05:30
credentials: '',
spreadsheetId: '',
range: '',
data: '',
2024-09-17 17:28:43 +05:30
});
2024-09-17 20:16:50 +05:30
const handleChange = (field: keyof IntegrationSettings) => (e: React.ChangeEvent<HTMLInputElement>) => {
2024-09-17 20:10:51 +05:30
setSettings({ ...settings, [field]: e.target.value });
};
2024-09-17 17:28:43 +05:30
return (
<GenericModal
isOpen={isOpen}
onClose={handleClose}
modalStyle={modalStyle}
>
<div style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
marginLeft: '65px',
}}>
2024-09-17 20:10:51 +05:30
<Typography sx={{ margin: '20px 0px' }}>Google Sheets Integration</Typography>
<TextField
sx={{ marginBottom: '15px' }}
label="Service Account JSON"
multiline
rows={10}
required
value={settings.credentials}
onChange={handleChange('credentials')}
fullWidth
/>
2024-09-17 17:28:43 +05:30
<TextField
sx={{ marginBottom: '15px' }}
2024-09-17 20:10:51 +05:30
label="Google Spreadsheet ID"
2024-09-17 17:28:43 +05:30
required
2024-09-17 20:10:51 +05:30
value={settings.spreadsheetId}
onChange={handleChange('spreadsheetId')}
fullWidth
2024-09-17 17:28:43 +05:30
/>
2024-09-17 20:10:51 +05:30
2024-09-17 17:28:43 +05:30
<TextField
sx={{ marginBottom: '15px' }}
2024-09-17 20:10:51 +05:30
label="Range (e.g., Sheet1!A1:B2)"
2024-09-17 17:28:43 +05:30
required
2024-09-17 20:10:51 +05:30
value={settings.range}
onChange={handleChange('range')}
fullWidth
2024-09-17 17:28:43 +05:30
/>
2024-09-17 20:10:51 +05:30
<TextField
sx={{ marginBottom: '15px' }}
label="Data (comma-separated, newline for rows)"
multiline
rows={4}
value={settings.data}
onChange={handleChange('data')}
fullWidth
/>
<Button variant="contained" color="primary" onClick={() => handleSubmit(settings)} style={{ marginTop: '10px' }}>
Submit
</Button>
2024-09-17 17:28:43 +05:30
</div>
</GenericModal>
);
2024-09-17 20:10:51 +05:30
};