Skip to content

Instantly share code, notes, and snippets.

@arnausd23
Last active September 6, 2021 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnausd23/5f18c77bdbc56216244319495beaf2de to your computer and use it in GitHub Desktop.
Save arnausd23/5f18c77bdbc56216244319495beaf2de to your computer and use it in GitHub Desktop.
// 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