Skip to content

Commit

Permalink
Update tsconfig & new port (#22)
Browse files Browse the repository at this point in the history
* Add eslint rule & setup port

* Update tsconfig
  • Loading branch information
krzysztofzuraw authored Oct 14, 2024
1 parent 0e6bc44 commit 455db23
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "next build",
"check-types": "tsc --noEmit",
"dev": "next dev",
"dev": "next dev --port 3001",
"fetch-schema": "curl https://raw.githubusercontent.com/saleor/saleor/${npm_package_saleor_schemaVersion}/saleor/graphql/schema.graphql > ./schema.graphql",
"gql-check": "gql.tada check",
"gql-generate": "gql.tada generate output",
Expand Down
3 changes: 1 addition & 2 deletions src/components/form-button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Loader2 } from "lucide-react";
import React from "react";

import { Button, ButtonProps } from "./ui/button";
import { Button, type ButtonProps } from "./ui/button";

interface FormButtonProps extends ButtonProps {
loading?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Slot } from "@radix-ui/react-slot";
import * as React from "react";
import {
Controller,
ControllerProps,
FieldPath,
FieldValues,
type ControllerProps,
type FieldPath,
type FieldValues,
FormProvider,
useFormContext,
} from "react-hook-form";
Expand Down
10 changes: 3 additions & 7 deletions src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ILogObj, ILogObjMeta, Logger } from "tslog";
import { type ILogObj, type ILogObjMeta, Logger } from "tslog";

import { env } from "@/env";

Expand Down Expand Up @@ -46,18 +46,14 @@ export const logger = new Logger<ILogObj>({
});

logger.attachTransport((log) => {
const {
message,
attributes,
_meta: { name },
} = log as ILogObj &
const { message, attributes, meta } = log as ILogObj &
ILogObjMeta & {
message: string;
attributes: Record<string, unknown>;
};

// eslint-disable-next-line no-console
console.log(`${name}: ${message}`, JSON.stringify(attributes, null, 2));
console.log(`${meta?.name}: ${message}`, JSON.stringify(attributes, null, 2));
});

export const createLogger = (name: string, params?: Record<string, unknown>) =>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/checkout-details/components/billing.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { FragmentOf, readFragment } from "gql.tada";
import { type FragmentOf, readFragment } from "gql.tada";
import { useForm } from "react-hook-form";
import * as z from "zod";

Expand Down
4 changes: 2 additions & 2 deletions src/modules/checkout-details/components/delivery-method.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import { FragmentOf, readFragment } from "gql.tada";
import { type FragmentOf, readFragment } from "gql.tada";
import { useForm } from "react-hook-form";
import * as z from "zod";

Expand Down Expand Up @@ -68,7 +68,7 @@ export const DeliveryMethod = (props: {
}
// if there is only one shipping method, return its id
if (shippingMethods.length === 1) {
return shippingMethods[0].id;
return shippingMethods[0]?.id;
}
// otherwise, return empty string
return "";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/checkout-details/components/shipping.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { FragmentOf, readFragment } from "gql.tada";
import { type FragmentOf, readFragment } from "gql.tada";
import { useForm } from "react-hook-form";
import * as z from "zod";

Expand Down
3 changes: 0 additions & 3 deletions src/modules/dropin/actions/initalize-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import { z } from "zod";

import { envUrlSchema } from "@/lib/env-url";
import { BaseError, UnknownError } from "@/lib/errors";
import { createLogger } from "@/lib/logger";
import { actionClient } from "@/lib/safe-action";

import { InitalizeTransactionSchema } from "../schemas";

const logger = createLogger("initalizeTransaction");

const initalizeTransactionMutation = graphql(`
mutation InitalizeTransaction(
$checkoutId: ID!
Expand Down
3 changes: 0 additions & 3 deletions src/modules/dropin/actions/process-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import { z } from "zod";

import { envUrlSchema } from "@/lib/env-url";
import { BaseError, UnknownError } from "@/lib/errors";
import { createLogger } from "@/lib/logger";
import { actionClient } from "@/lib/safe-action";

import { TransactionProcessSchema } from "../schemas/transaction-process";

const logger = createLogger("processTransaction");

const processTransactionMutation = graphql(`
mutation transactionProcess($transactionId: ID!, $data: JSON) {
transactionProcess(id: $transactionId, data: $data) {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/dropin/adyen/gateway-config-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createLogger } from "@/lib/logger";

import {
GiftCardBalanceResponseSchema,
InitalizePaymentGatewaySchemaType,
type InitalizePaymentGatewaySchemaType,
OrderCancelResponseSchema,
OrderCreateResponseSchema,
} from "../schemas";
Expand All @@ -25,7 +25,7 @@ export class AdyenGiftCardBalanceResponse {
);
}
return new AdyenGiftCardBalanceResponse(
data.paymentGatewayInitialize.gatewayConfigs[0].data.giftCardBalanceResponse,
data.paymentGatewayInitialize.gatewayConfigs[0]?.data.giftCardBalanceResponse,
);
}

Expand All @@ -48,7 +48,7 @@ export class AdyenOrderCreateResponse {
);
}
return new AdyenOrderCreateResponse(
data.paymentGatewayInitialize.gatewayConfigs[0].data.orderCreateResponse,
data.paymentGatewayInitialize.gatewayConfigs[0]?.data.orderCreateResponse,
);
}

Expand All @@ -71,7 +71,7 @@ export class AdyenOrderCancelledResponse {
);
}
return new AdyenOrderCancelledResponse(
data.paymentGatewayInitialize.gatewayConfigs[0].data.orderCancelResponse,
data.paymentGatewayInitialize.gatewayConfigs[0]?.data.orderCancelResponse,
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/modules/dropin/components/adyen-dropin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import "@adyen/adyen-web/dist/adyen.css";

import AdyenCheckout from "@adyen/adyen-web";
import { FragmentOf, readFragment } from "gql.tada";
import { type FragmentOf, readFragment } from "gql.tada";
import { useEffect, useRef } from "react";

import { getAdyenDropinConfig } from "../adyen";
import { TotalPriceFragment } from "../fragments";
import { InitalizePaymentGatewaySchemaType } from "../schemas";
import { type InitalizePaymentGatewaySchemaType } from "../schemas";

export const AdyenDropin = (props: {
initalizePaymentGatewayData: InitalizePaymentGatewaySchemaType;
Expand All @@ -25,7 +25,8 @@ export const AdyenDropin = (props: {
checkoutId,
paymentGatewayId,
} = props;
const gatewayConfig = gatewayConfigs[0];
// there are always going to be at least one gateway config
const gatewayConfig = gatewayConfigs[0]!;
const { clientKey, environment, paymentMethodsResponse } = gatewayConfig.data;
const totalPrice = readFragment(TotalPriceFragment, totalPriceData);
const dropinContainerRef = useRef<HTMLDivElement | null>(null);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/environment/components/cart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { FragmentOf, readFragment } from "gql.tada";
import { type FragmentOf, readFragment } from "gql.tada";
import Image from "next/image";
import { useTransition } from "react";

Expand All @@ -27,7 +27,7 @@ export const Cart = (props: {
const response = await createCheckout({
envUrl,
channelSlug,
variantId: products[0].defaultVariant?.id ?? "",
variantId: products[0]?.defaultVariant?.id ?? "",
});

if (response?.serverError) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/environment/components/environment.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { FragmentOf } from "gql.tada";
import { type FragmentOf } from "gql.tada";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { FragmentOf, readFragment } from "gql.tada";
import { type FragmentOf, readFragment } from "gql.tada";
import { useForm } from "react-hook-form";
import { z } from "zod";

Expand Down Expand Up @@ -45,7 +45,7 @@ export const PaymentGatewaySelect = (props: {
const getDefaultPaymentGatewayId = () => {
// if there is only one available payment gateway, return its id
if (availablePaymentGateways.length === 1) {
return availablePaymentGateways[0].id;
return availablePaymentGateways[0]?.id;
}
// otherwise, return empty string
return "";
Expand Down
3 changes: 0 additions & 3 deletions src/modules/summary/actions/get-checkout-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import { z } from "zod";

import { envUrlSchema } from "@/lib/env-url";
import { BaseError, UnknownError } from "@/lib/errors";
import { createLogger } from "@/lib/logger";
import { actionClient } from "@/lib/safe-action";

import { CheckoutFragment } from "../fragments";

const logger = createLogger("getCheckoutSummary");

const GetCheckoutSummaryQuery = graphql(
`
query getCheckoutSummary($checkoutId: ID!) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/summary/components/summary.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { lightFormat } from "date-fns";
import { FragmentOf, readFragment } from "gql.tada";
import { type FragmentOf, readFragment } from "gql.tada";
import { Copy, SquareArrowOutUpRight } from "lucide-react";
import Link from "next/link";
import { useTransition } from "react";
Expand Down
23 changes: 16 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"esModuleInterop": true,
"skipLibCheck": true,
"allowJs": true,
"resolveJsonModule": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"incremental": true,

"strict": true,
"noEmit": true,
"esModuleInterop": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,

"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,

"lib": ["dom", "dom.iterable", "esnext"],
"jsx": "preserve",
"incremental": true,

"plugins": [
{
"name": "next"
Expand Down

0 comments on commit 455db23

Please sign in to comment.