Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add order purchase callback #37

Merged
merged 7 commits into from
Jul 10, 2024
Merged

Add order purchase callback #37

merged 7 commits into from
Jul 10, 2024

Conversation

hvergara
Copy link
Contributor

@hvergara hvergara commented Jul 2, 2024

Improves purchase callback logic. Note: design & localization will be improved in future PRs, setting up minimal UI for now.

Copy link

cloudflare-workers-and-pages bot commented Jul 2, 2024

Deploying tickets with  Cloudflare Pages  Cloudflare Pages

Latest commit: a2c8f72
Status: ✅  Deploy successful!
Preview URL: https://7c9d62c7.tickets.pages.dev
Branch Preview URL: https://hvergara-purchase-callback.tickets.pages.dev

View logs


useEffect(() => {
if (!triggered.current) {
void checkPurchaseOrder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podemos llamar al checkPurchaseOrderMutation directo y nos ahorramos un useCallback.
Porque el checkPurchaseOrderMutation no cambia si se renderiza el componente.


useEffect(() => {
if (!triggered.current) {
void checkPurchaseOrder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tangencial, pero re pocas veces veo void 🤔 no se si derepente me estoy perdiendo algo... Pero si no estamos retornando checkPurchaseOrder es necesario? O es mas estilistico?

export const PurchaseCallback = ({
purchaseOrderId,
}: PurchaseCallbackProps) => {
const triggered = useRef(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tenemos un estandar definido, pero prefiero usar refs para dom nodes, o referencias que necesitemos que no se regeneren. (Onda setInterval por ejemplo...)

Podemos conversarlo, pero soy mas partidario de errar hacia el useState por convención/default

const purchaseOrderId = params.get("purchaseOrderId");

if (!purchaseOrderId) {
return toast("Error fetching purchase order");
Copy link
Member

@fforres fforres Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toast retorna undefined, asi que tecnicamente esto esta bien. Pero como toast no es un componente, creo que seria mejor o un poco mas claro, que retornaramos null aca y que dejaramos el toast en un useEffect

useEffect(() => {
    if(!purchaseOrderId) {
		toast("Error fetching purchase order");
    }
}, [purchaseOrderId])

@fforres fforres enabled auto-merge (squash) July 10, 2024 03:06
@fforres fforres disabled auto-merge July 10, 2024 03:08
@fforres fforres merged commit 588c6ab into main Jul 10, 2024
4 checks passed
@fforres fforres deleted the hvergara/purchase-callback branch July 10, 2024 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants