Ecommerce Shopify WordPress Discussion

How to access the action method data in the remix?

I made a GraphQL call from the action method and got the URL in the response. In the action, I want to redirect that URL but I am not able to get the window object in the action method that's why I am trying to use the useActionData method. But the problem is I am not able to get the URL on the first click. I got the URL after second time when I had to click the button. Below is my code. export async function action({request}){ const { admin, session } = await authenticate.admin(request); const shop = await session.shop; const graphql = await admin.graphql; const data = Object.fromEntries(await request.formData()) const plan_50kg = await db.plans.findUnique({ where: { id: 4 } }); const shopName = await shop.split('.')[0]; const appName = process.env.APP_NAME; const args_50kg = { "name":"Super Duper Capped Pricing Plan", "return_url": "https://admin.shopify.com/store/"+shopName+"/apps/"+appName+"/app", "terms": "$"+plan_50kg?.usage_charges+" USD every 30 days", "cappedAmount": { "amount": ""+plan_50kg?.capped_amount+"", "currencyCode": "USD" }, "price": { "amount": ""+plan_50kg?.price+"", "currencyCode": "USD" } } const confirmation_url_50kg = await createSubscription(args_50kg, graphql); return json({ confirmation_url: confirmation_url_50kg, }); } const Pricing = () => { const data = useActionData(); <Form method="post"> <input type="hidden" value="1" name="plan_id"></input> <input type="hidden" name="plan_id"></input> <Button submit primary onClick={()=>{ console.log("data", data); }}>Unsubscribe</Button> </Form> }
To redirect from inside your action, use the redirect method. import { redirect } from "@remix-run/node"; export async function action({request}){ // ... const confirmation_url_50kg = await createSubscription(args_50kg, graphql); return redirect(confirmation_url_50kg); } https://remix.run/docs/en/main/utils/redirect

December 30, 2023

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.