-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd202d9
commit 40df4d9
Showing
29 changed files
with
531 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
export const createAddaptedUser = (user: any) => { | ||
const formattedUser: any = { | ||
id: user.id, | ||
name: user.name, | ||
email: user.email, | ||
}; | ||
return formattedUser; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class UserRepository {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { User } from "firebase/auth"; | ||
import { | ||
FirestoreTransactionRepository, | ||
LocalStorageTransactionRepository, | ||
} from "../Infrastructure"; | ||
import { FirestoreTransactionUseCases, LocalStorageTransactionUseCases } from "../../usecases"; | ||
import { Transaction } from "../../domain/entities"; | ||
|
||
export class SyncTransactionsService { | ||
private storageKey: string = import.meta.env.VITE_REACT_APP_LOCALSTORAGE_KEY; | ||
private localStorageTransactionUseCases: LocalStorageTransactionUseCases; | ||
private firestoreTransactionUseCases: FirestoreTransactionUseCases; | ||
|
||
constructor(private user: User | null) { | ||
const localStorageTransactionRepository = new LocalStorageTransactionRepository(); | ||
const firestoreTransactionRepository = new FirestoreTransactionRepository(); | ||
|
||
this.localStorageTransactionUseCases = new LocalStorageTransactionUseCases( | ||
localStorageTransactionRepository, | ||
); | ||
this.firestoreTransactionUseCases = new FirestoreTransactionUseCases( | ||
firestoreTransactionRepository, | ||
); | ||
} | ||
|
||
public async detectSyncTransactions(): Promise<void> { | ||
const localStorageTransactions = await this.localStorageTransactionUseCases.getTransactions(); | ||
if (localStorageTransactions.length > 0) { | ||
await this.wantsToSync(localStorageTransactions); | ||
} else { | ||
// Llamar al método getTransactions() en el componente homePage | ||
} | ||
} | ||
|
||
private async wantsToSync(transactions: Transaction[]): Promise<void> { | ||
const userConfirmed = window.confirm( | ||
"Tienes transacciones no guardadas. ¿Deseas sincronizarlas?", | ||
); | ||
if (userConfirmed) { | ||
await this.syncTransactions(transactions); | ||
} else { | ||
// Llamar al método getTransactions() en el componente homePage | ||
} | ||
} | ||
|
||
private async syncTransactions(transactions: Transaction[]): Promise<void> { | ||
if (this.user) { | ||
await this.firestoreTransactionUseCases.uploadTransactions(transactions); | ||
} | ||
|
||
localStorage.removeItem(this.storageKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Category, Transaction } from "../entities/Transaction"; | ||
|
||
export interface ITransactionService { | ||
getTransactions(): Promise<Transaction[]>; | ||
addTransaction(data: Transaction, selectedCategory: Category): Promise<Transaction>; | ||
updateTransaction( | ||
id: string, | ||
updatedData: Partial<Transaction>, | ||
selectedCategory: Category, | ||
): Promise<Transaction | null>; | ||
deleteTransaction(id: string): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useAuth } from "reactfire"; | ||
import { AuthBasedTransactionService } from "../data/services/AuthBasedTransactionService"; | ||
|
||
const useAuthBasedTransactionService = () => { | ||
const auth = useAuth(); | ||
return new AuthBasedTransactionService(auth.currentUser); | ||
}; | ||
|
||
export { useAuthBasedTransactionService }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/presentation/components/sync-modal/SyncModal.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// import { Button, Flex, Modal, Result, Spin } from "antd"; | ||
// import { useState } from "react"; | ||
// import { useSyncTransactions } from "../../hooks/useSyncTransactions"; | ||
// import { useSyncModal } from "../../hooks/useSyncModal"; | ||
|
||
// type SyncState = "loading" | "success" | "error"; | ||
|
||
// const SyncModal: React.FC = () => { | ||
// const { SyncModal, closeSyncModal } = useSyncModal(); | ||
// const [state, setState] = useState(false); | ||
|
||
// const handleSetState = () => { | ||
// setState(true); | ||
// }; | ||
|
||
// return ( | ||
// <Modal open={SyncModal} onCancel={closeSyncModal} footer={null} width={430} closable={false}> | ||
// {!state ? ( | ||
// <SyncConfirm onClose={closeSyncModal} onConfirm={handleSetState} /> | ||
// ) : ( | ||
// <Sync onClose={closeSyncModal} /> | ||
// )} | ||
// </Modal> | ||
// ); | ||
// }; | ||
|
||
// interface SyncConfirmProps { | ||
// onClose: () => void; | ||
// onConfirm: () => void; | ||
// } | ||
|
||
// const SyncConfirm: React.FC<SyncConfirmProps> = ({ onClose, onConfirm }) => { | ||
// const transactionsLength = 2; | ||
|
||
// return ( | ||
// <> | ||
// <Result | ||
// status="info" | ||
// title={`Hay ${transactionsLength} ${transactionsLength > 1 ? "transacciones" : "transacción"} sin sincronizar`} | ||
// subTitle="¿Deseas sincronizarlas?" | ||
// /> | ||
// <Flex gap={8}> | ||
// <Button block danger onClick={onClose}> | ||
// Descartar | ||
// </Button> | ||
// <Button block type="primary" onClick={onConfirm}> | ||
// Confirmar | ||
// </Button> | ||
// </Flex> | ||
// </> | ||
// ); | ||
// }; | ||
|
||
// const Sync: React.FC<{ onClose: () => void }> = ({ onClose }) => { | ||
// // const [syncState, setSyncState] = useState<SyncState>("loading"); | ||
// // useSyncTransactions(syncState, setSyncState); | ||
|
||
// return ( | ||
// <> | ||
// {syncState === "loading" && ( | ||
// <Flex justify="center" vertical> | ||
// <div style={{ paddingBlock: 150 }}> | ||
// <Spin tip="Sincronizando..." size="large"> | ||
// {null} | ||
// </Spin> | ||
// </div> | ||
// </Flex> | ||
// )} | ||
// {syncState === "success" && ( | ||
// <Result | ||
// status="success" | ||
// title="Transacciones sincronizadas" | ||
// subTitle="Las transacciones han sido sincronizadas con exito" | ||
// extra={[ | ||
// <Button block type="primary" onClick={onClose}> | ||
// Cerrar | ||
// </Button>, | ||
// ]} | ||
// /> | ||
// )} | ||
// {syncState === "error" && ( | ||
// <Result | ||
// status="error" | ||
// title="Transacciones no sincronizadas" | ||
// subTitle="Las transacciones no han sido sincronizadas" | ||
// /> | ||
// )} | ||
// </> | ||
// ); | ||
// }; | ||
|
||
// export default SyncModal; |
Oops, something went wrong.