Skip to content

Commit 35c3e0a

Browse files
committed
Update routes to use react-router generated types
1 parent 75e29ca commit 35c3e0a

File tree

8 files changed

+53
-54
lines changed

8 files changed

+53
-54
lines changed

.eslintrc.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ module.exports = {
6969
},
7070
},
7171
},
72+
rules: {
73+
"import/no-unresolved": [
74+
"error",
75+
{
76+
ignore: ["^\\./\\+types/"],
77+
},
78+
],
79+
},
7280
extends: [
7381
"plugin:@typescript-eslint/recommended",
7482
"plugin:import/recommended",

app/routes/_index/route.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import type { LoaderFunctionArgs } from "react-router";
1+
import { Route } from "./+types/route";
22
import { redirect, Form, useLoaderData } from "react-router";
3-
43
import { login } from "../../shopify.server";
5-
64
import styles from "./styles.module.css";
75

8-
export const loader = async ({ request }: LoaderFunctionArgs) => {
6+
export const loader = async ({ request }: Route.LoaderArgs) => {
97
const url = new URL(request.url);
108

119
if (url.searchParams.get("shop")) {

app/routes/app._index.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1+
import { Route } from "./+types/app._index";
12
import { useEffect } from "react";
2-
import type {
3-
ActionFunctionArgs,
4-
HeadersFunction,
5-
LoaderFunctionArgs,
6-
} from "react-router";
73
import { useFetcher } from "react-router";
84
import { useAppBridge } from "@shopify/app-bridge-react";
95
import { authenticate } from "../shopify.server";
106
import { boundary } from "@shopify/shopify-app-react-router/server";
117

12-
export const loader = async ({ request }: LoaderFunctionArgs) => {
8+
export const loader = async ({ request }: Route.LoaderArgs) => {
139
await authenticate.admin(request);
1410

1511
return null;
1612
};
1713

18-
export const action = async ({ request }: ActionFunctionArgs) => {
14+
export const action = async ({ request }: Route.ActionArgs) => {
1915
const { admin } = await authenticate.admin(request);
2016
const color = ["Red", "Orange", "Yellow", "Green"][
2117
Math.floor(Math.random() * 4)
@@ -248,6 +244,6 @@ export default function Index() {
248244
);
249245
}
250246

251-
export const headers: HeadersFunction = (headersArgs) => {
247+
export const headers: Route.HeadersFunction = (headersArgs) => {
252248
return boundary.headers(headersArgs);
253249
};

app/routes/app.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { HeadersFunction, LoaderFunctionArgs } from "react-router";
1+
import { Route } from "./+types/app";
22
import { Outlet, useLoaderData, useRouteError } from "react-router";
33
import { boundary } from "@shopify/shopify-app-react-router/server";
44
import { AppProvider } from "@shopify/shopify-app-react-router/react";
5-
65
import { authenticate } from "../shopify.server";
76

8-
export const loader = async ({ request }: LoaderFunctionArgs) => {
7+
export const loader = async ({ request }: Route.LoaderArgs) => {
98
await authenticate.admin(request);
109

1110
// eslint-disable-next-line no-undef
@@ -31,6 +30,6 @@ export function ErrorBoundary() {
3130
return boundary.error(useRouteError());
3231
}
3332

34-
export const headers: HeadersFunction = (headersArgs) => {
33+
export const headers: Route.HeadersFunction = (headersArgs) => {
3534
return boundary.headers(headersArgs);
3635
};

app/routes/auth.$.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
2-
import type { HeadersFunction, LoaderFunctionArgs } from "react-router";
1+
import { Route } from "./+types/auth.$";
32
import { authenticate } from "../shopify.server";
43
import { boundary } from "@shopify/shopify-app-react-router/server";
54

6-
export const loader = async ({ request }: LoaderFunctionArgs) => {
5+
export const loader = async ({ request }: Route.LoaderArgs) => {
76
await authenticate.admin(request);
87

98
return null;
109
};
1110

12-
export const headers: HeadersFunction = (headersArgs) => {
11+
export const headers: Route.HeadersFunction = (headersArgs) => {
1312
return boundary.headers(headersArgs);
1413
};

app/routes/auth.login/route.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1+
import { Route } from "./+types/route";
12
import { AppProvider } from "@shopify/shopify-app-react-router/react";
23
import { useState } from "react";
3-
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
44
import { Form, useActionData, useLoaderData } from "react-router";
5-
65
import { login } from "../../shopify.server";
76
import { loginErrorMessage } from "./error.server";
87

9-
export const loader = async ({ request }: LoaderFunctionArgs) => {
8+
export const loader = async ({ request }: Route.LoaderArgs) => {
109
const errors = loginErrorMessage(await login(request));
1110

1211
return { errors };
1312
};
1413

15-
export const action = async ({ request }: ActionFunctionArgs) => {
14+
export const action = async ({ request }: Route.ActionArgs) => {
1615
const errors = loginErrorMessage(await login(request));
1716

1817
return {
@@ -30,18 +29,18 @@ export default function Auth() {
3029
<AppProvider embedded={false}>
3130
<s-page>
3231
<Form method="post">
33-
<s-section heading="Log in">
34-
<s-text-field
35-
name="shop"
36-
label="Shop domain"
37-
details="example.myshopify.com"
38-
value={shop}
39-
onChange={(e) => setShop(e.currentTarget.value)}
40-
autocomplete="on"
41-
error={errors.shop}
42-
></s-text-field>
43-
<s-button type="submit">Log in</s-button>
44-
</s-section>
32+
<s-section heading="Log in">
33+
<s-text-field
34+
name="shop"
35+
label="Shop domain"
36+
details="example.myshopify.com"
37+
value={shop}
38+
onChange={(e) => setShop(e.currentTarget.value)}
39+
autocomplete="on"
40+
error={errors.shop}
41+
></s-text-field>
42+
<s-button type="submit">Log in</s-button>
43+
</s-section>
4544
</Form>
4645
</s-page>
4746
</AppProvider>
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import type { ActionFunctionArgs } from "react-router";
1+
import { Route } from "./+types/webhooks.app.scopes_update";
22
import { authenticate } from "../shopify.server";
33
import db from "../db.server";
44

5-
export const action = async ({ request }: ActionFunctionArgs) => {
6-
const { payload, session, topic, shop } = await authenticate.webhook(request);
7-
console.log(`Received ${topic} webhook for ${shop}`);
5+
export const action = async ({ request }: Route.ActionArgs) => {
6+
const { payload, session, topic, shop } = await authenticate.webhook(request);
7+
console.log(`Received ${topic} webhook for ${shop}`);
88

9-
const current = payload.current as string[];
10-
if (session) {
11-
await db.session.update({
12-
where: {
13-
id: session.id
14-
},
15-
data: {
16-
scope: current.toString(),
17-
},
18-
});
19-
}
20-
return new Response();
9+
const current = payload.current as string[];
10+
if (session) {
11+
await db.session.update({
12+
where: {
13+
id: session.id,
14+
},
15+
data: {
16+
scope: current.toString(),
17+
},
18+
});
19+
}
20+
return new Response();
2121
};

app/routes/webhooks.app.uninstalled.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { ActionFunctionArgs } from "react-router";
1+
import { Route } from "./+types/webhooks.app.uninstalled";
22
import { authenticate } from "../shopify.server";
33
import db from "../db.server";
44

5-
export const action = async ({ request }: ActionFunctionArgs) => {
5+
export const action = async ({ request }: Route.ActionArgs) => {
66
const { shop, session, topic } = await authenticate.webhook(request);
77

88
console.log(`Received ${topic} webhook for ${shop}`);

0 commit comments

Comments
 (0)