Skip to content

Commit

Permalink
New: Add the Otp Modal (#619)
Browse files Browse the repository at this point in the history
Co-authored-by: Baruch Odem <baruchiro@gmail.com>
  • Loading branch information
shaiu and baruchiro authored Nov 25, 2024
1 parent d2d5b79 commit d8c5f47
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/main/src/backend/eventEmitters/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum EventNames {
IMPORTER_ERROR = 'IMPORTER_ERROR',
IMPORTER_END = 'IMPORTER_END',
IMPORT_PROCESS_END = 'IMPORT_PROCESS_END',
GET_OTP = 'GET_OTP',
EXPORT_PROCESS_START = 'EXPORT_PROCESS_START',
EXPORTER_START = 'EXPORTER_START',
EXPORTER_PROGRESS = 'EXPORTER_PROGRESS',
Expand Down Expand Up @@ -131,6 +132,7 @@ export interface EventDataMap {
[EventNames.IMPORTER_PROGRESS]: ImporterEvent;
[EventNames.IMPORTER_ERROR]: ImporterEvent;
[EventNames.IMPORTER_END]: ImporterEvent;
[EventNames.GET_OTP]: undefined;
[EventNames.IMPORT_PROCESS_END]: undefined;
[EventNames.EXPORT_PROCESS_START]: undefined;
[EventNames.EXPORT_PROCESS_END]: undefined;
Expand Down
4 changes: 4 additions & 0 deletions packages/preload/src/eventsBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ export async function electronGoogleOAuth2Connector(): Promise<Credentials> {
export async function createSpreadsheet(spreadsheetId: string, credentials: Credentials): Promise<string> {
return electron.ipcRenderer.invoke('createSpreadsheet', spreadsheetId, credentials);
}

export function sendOTPResponse(input: string) {
electron.ipcRenderer.invoke('get-otp-response', input);
}
56 changes: 56 additions & 0 deletions packages/renderer/src/components/GetOtp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useEffect, useState } from 'react';
import { Button, FormControl, Modal } from 'react-bootstrap';
import { observer } from 'mobx-react-lite';
import { useConfigStore } from '/@/store/ConfigStore';
import { sendOTPResponse } from '#preload';

const GetOtp = () => {
const configStore = useConfigStore();
const [modalStatus, setModalStatus] = useState<boolean>(false);
const [inputText, setInputText] = useState('');

const closeModal = (inputText = '') => {
sendOTPResponse(inputText);
setModalStatus(false);
};

useEffect(() => {
if (configStore.getOtp !== undefined) {
setModalStatus(configStore.getOtp);
}
}, [configStore.getOtp]);

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputText(e.target.value);
};

const sendInput = async (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();

closeModal(inputText);
};

if (!configStore.getOtp) {
return null;
}

return (
<Modal show={modalStatus} onHide={closeModal}>
<Modal.Header closeButton></Modal.Header>
<Modal.Body>
<FormControl
type="text"
placeholder="Enter text here"
value={inputText}
onChange={handleInputChange}
className="mb-3"
/>
<Button variant="dark" name="send-report" type="submit" onClick={sendInput}>
הכנס קוד
</Button>
</Modal.Body>
</Modal>
);
};

export default observer(GetOtp);
4 changes: 4 additions & 0 deletions packages/renderer/src/store/ConfigStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class ConfigStore {
config: Config;

chromeDownloadPercent = 0;
getOtp: boolean | undefined = undefined;

// TODO: move this to a separate store
accountScrapingData: Map<CompanyTypes | OutputVendorName, AccountScrapingData>;
Expand Down Expand Up @@ -155,6 +156,9 @@ export class ConfigStore {
if (eventName === 'DOWNLOAD_CHROME') {
this.updateChromeDownloadPercent((budgetTrackingEvent as DownloadChromeEvent)?.percent);
}
if (eventName == 'GET_OTP') {
this.getOtp = true;
}
if (budgetTrackingEvent) {
const accountId = budgetTrackingEvent.vendorId;
if (accountId) {
Expand Down

0 comments on commit d8c5f47

Please sign in to comment.