DukeRupert / rr-wholesale-frontend

Customer facing website for Rockabilly Roasting wholesale services.
https://rr-wholesale-frontend.vercel.app
3 stars 0 forks source link

ProductList form not invalidating. #1

Open korur opened 10 months ago

korur commented 10 months ago

Thanks for the repo! I am exploring sveltekit and medusajs as well.

When i add a product to the cart, I see that quantity does not get reset in the products table.

In the ProductList.svelte file, I think you should use update() function instead of invalidateAll() as below

<form
    action="/cart?/add"
    use:enhance={({ formData }) => {
        const quantity = formData.get('quantity');
        return async ({ result, update }) => {
            if (result.type === 'success') {
                addToast({
                    data: {
                        type: 'success',
                        title: 'Success',
                        description: `${quantity} ${variant.title} added to cart`
                    }
                });

                // await invalidateAll();
                update();
            }

https://kit.svelte.dev/docs/form-actions#progressive-enhancement-customising-use-enhance

korur commented 10 months ago

another issue was the shipping address always reverting to default if i edit it. Seems to be fixed by removing below function from the load function in checkout/+page.server.ts. Load function reruns after action="?/updateShippingAddress" is called.

    // If user has an associated shipping address then update the cart with it
    console.log('Checking for valid shipping address');
    if (locals.user?.shipping_addresses && locals.user.shipping_addresses.length > 0) {
        console.log('Found saved address. Setting index 0 as cart shipping address');
        const saved_address = locals.user.shipping_addresses[0]
        console.log(saved_address)
        const isValid = shippingAddressSchema.safeParse(saved_address);
        if(!isValid.success) console.log(isValid.error)
        if (isValid.success) {
            console.log('Setting shipping address as default');
            const { first_name, last_name, company, address_1, address_2, city, province, postal_code } =
                isValid.data;
            const defaultAddress = {
                first_name,
                last_name,
                company,
                address_1,
                address_2,
                city,
                province,
                postal_code,
                country_code: 'us'
            };
            cart = (await medusa.updateCartShippingAddress(locals, defaultAddress)) as Cart;
        }
DukeRupert commented 10 months ago

Hi @korur, your inputs are appreciated! As you can see this is a work in progress. Just for context it is intended to be the front-end for a business to business (B2B) coffee roasting wholesale company.

DukeRupert commented 10 months ago

Ok, the changes you suggested have been pushed in the last couple commits. I'll leave this thread open for a few days in case catch anything else :)

korur commented 10 months ago

Thanks @DukeRupert. Initially, I explored Pevey's repository, but had some other issues there. Then, I came across your repo and noticed that you've been actively adding new features in recent days. I found it to be an excellent resource for learning for me. It looks pretty nice as well! Tailwind is great :)

Actually curious about how to implement the payment/stripe functionality.. haven't done it before and heard that the Stripe API changed recently.

Will let you know if i came across something else!

DukeRupert commented 10 months ago

After this project is done I'll be building a customer facing storefront for the same company which will use stripe subscriptions / payments to enable the e-commerce side. I spun up a brief proof-of-concept using Pevey's starter that seemed to work alright with stripe once I stripped out the Turnstile integration. The stripe integration worked well for capturing payment but there is no support for subscriptions at this time. I'll have to write a plugin for that.

korur commented 10 months ago

Actually, after your comment I tried again Pevey's repo today (mostly it was my mistake that stripe on the backend was not set properly), and everything worked even with the turnstile. There is a typo somewhere assigning the "token" instead of an equality check. (I needed to add turnstile "test keys" from cloudflare as well.)