Last active
September 6, 2021 06:53
-
-
Save arnausd23/5f18c77bdbc56216244319495beaf2de to your computer and use it in GitHub Desktop.
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
// use case: Retrieve user Quonto information | |
/* Quonto service layer: */ | |
/* This layer does HTTP calls to our APIs */ | |
connectToQuonto = () => Promise<Token | Error> | |
readUserInformation = (token) => Promise<User | Error> | |
/* Use case layer: */ | |
/* Handle domain logic */ | |
retrieveUserQuontoInformation = async (onSuccess, onError) => { | |
try { | |
const token = await connectToQuonto() | |
const data = await readUserInformation(token) | |
onSuccess(data) | |
} catch(error) { | |
const errorType = errorCode | |
onError(errorType, errorDescription) | |
} | |
} | |
/* Container (view) layer */ | |
const QuontoContainer = () => { | |
const [data, setData] = useState<User | null>(null) | |
const handleError = (errorType, errorDescription) => { | |
switch(errorType) { | |
case "globalError": | |
return toast.error(errorDescription) | |
// ... | |
} | |
} | |
useEffect(() => { | |
retrieveUserQuontoInformation(setData, handleError) | |
}, []) | |
return ( | |
<QuontonDumbComponent {...data} /> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment