Skip to content

Commit

Permalink
21 web handle currency (#104)
Browse files Browse the repository at this point in the history
* add: currency/api lib

* fix: writeToFile rates

* rebase

* fix: writeToFile rates

* add: next-currency-cache functions

* add: setRates cron job

* fix: next/currency-cache to ts config

* fix: linter unknow instead of any

* fix: linter unknow instead of any

* fix: uncomment important code

* fix: tests for currency/api and currency-cache

* rebase

fix: writeToFile rates

add: currency/api lib

fix: writeToFile rates

add: next-currency-cache functions

add: setRates cron job

fix: linter unknow instead of any

fix: linter unknow instead of any

fix: uncomment important code

fix: tests for currency/api and currency-cache

* add env variables changes and @shared/server to get env info

* fix: fix tests for currency-cache

* tsconfig add

* add: CurrencyProvider and provider settings

* fix: tsconfig.base.json

* add: currency-dropdown ui/components and icons

* fix: global settings props

* 🔧 chore(sentry.client.config.ts): remove unused code and simplify SENTRY_DSN assignment

* fix: usecontext back in eventpasses

* fix: currency provider in preview

* 🔧 chore(package.json): remove esbuild dependency to simplify the project dependencies
📦 feat(project.json): add project.json file to configure a local registry target for nx using verdaccio executor

* fix: currency settings and revalidateTag

* fix: isJestRunning for setRates tests

* test: without loading

* correct old version

* fix: currencyProvider

* fix: comment test rates

* fix: test without eventpasses

* fix: remove all formatCurrency

* fix: remove all formatCurrency

* fix: remove all formatCurrency in SinglePass

* fix: remove getREates from currencyProvider

* fix: put back tsconfig about storybook

* fix: getRates in currency provider with rfetch

* fix: PassTotal uncommented

* fix: PassTotal without loading

* fix: check if it's a test and return false rates

* 📦 chore(env-nextjs.mock.js): add mock file for @t3-oss/env-nextjs module to be used in Storybook
📦 chore(main.ts): add alias for @t3-oss/env-nextjs module to use the mock file in Storybook
📦 chore(preview.tsx): remove unnecessary import of CurrencyProvider and add CurrencyDecorator to wrap stories with CurrencyProvider
🐛 fix(index.tsx): replace fetchRates function with getRates function from @next/currency-cache module to improve code readability and maintainability

* fix: check if fetchFromLocalFile is problem

* fix: display args to check

* fix: display all key value of objects

* fix: display all key values

* fix: send only the concerned rate to formatCurrency

* fix: toUserCurrency to take only the rate of the user currency

* 🐛 fix(index.ts): fix file path to use __dirname instead of process.cwd() to correctly locate rates directory
🔥 chore(index.ts): remove commented out code for fetching from local JSON files and return default rates instead
🔥 chore(examples.tsx): remove unused import of Link from '@next/navigation'

* fix: rates in lib and absolute path for __dirname

* fix: swcrc file for currency/types

* fix: storybook story

* 🔧 chore(jest.preset.js): add support for import.meta in jest configuration to avoid issues with import.meta
🔧 chore(jest.config.ts): remove unnecessary transform configuration for ts-jest in jest configuration
📦 chore(package.json): add ts-jest-mock-import-meta package as a dependency for jest configuration

* fix: fix tests with import.meta and new EUR.json

* fix: no frozen lockfile

* fix: no frozen lockfile

* 🔥 refactor(server.ts): change port variable case from lowercase port to uppercase PORT to improve semantics

🔧 chore(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port

🔥 refactor(types): remove unused .babelrc file

🔧 chore(types): update project.json and tsconfig.json paths for currency/types library

🔧 chore(createEventPassesSlice.ts): update import path for Money from @currency/types

✨ feat(cache): add .swcrc and package.json files

🔧 chore(cache): update project.json and tsconfig.json paths for next/cache library

🔧 chore(cache): update import path for Cache in next-currency-cache.spec.ts and next-currency-cache.ts

🔧 chore(currency): update tsconfig.json and tsconfig.lib.json files

🔧 chore(nft-thirdweb-api.ts): remove unused 'use server' statement

🔧 chore(tsconfig.base.json): remove unused import path for @next/cache/server

* 🐛 fix(nft-thirdweb-api.ts): add error handling for undefined SDK to prevent potential crashes
🔥 chore(payment-webhooks.spec.ts): remove unused payment webhooks test file

* 🔧 chore(.swcrc): remove unnecessary regex pattern from exclude list to improve code coverage
🔧 chore(jest.config.ts): update regex pattern to include .ts files in transform to improve code coverage
🔧 chore(payment-admin.ts): cast eventSlug and organizerSlug to string to avoid potential null or undefined values
🔧 chore(package.json): add @types/text-encoding dependency to fix ReferenceError: TextDecoder is not defined
🔧 chore(jest.setup.ts): import and assign TextEncoder and TextDecoder from text-encoding to fix ReferenceError: TextDecoder is not defined

* 🐛 fix(payment-admin.ts): throw an error if refund status is null to prevent unexpected behavior
🐛 fix(payment-webhooks.ts): remove unused line_items variable to improve code readability

* 🔧 fix(layout.tsx): remove unused import and update import path for Analytics component
🔧 fix(layout.tsx): update import path for siteConfig in Analytics component
🔧 fix(layout.tsx): add Metadata type import and define metadata object for page title
🔧 fix(next.config.js): remove unused appDir configuration

* 🔧 chore(tsconfig.base.json): optimize paths configuration for better readability and maintainability

* 🔧 chore(preview-apps.yml): remove 'staging' branch from branches-ignore list to enable preview apps for staging branch
🔒 chore(preview-apps.yml): add VERCEL_ORG_ID environment variable to enable deployment to Vercel preview apps

---------

Co-authored-by: sebpalluel <[email protected]>
  • Loading branch information
AlexandreG-tech and sebpalluel authored Oct 11, 2023
1 parent 5647996 commit 1a9ff58
Show file tree
Hide file tree
Showing 90 changed files with 2,450 additions and 165 deletions.
5 changes: 3 additions & 2 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ KV_REST_API_TOKEN="example_token"
## timezone
TZ=UTC


# NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=test
## currency
FIXER_CURRENCY_API_KEY='0f0ab52ebe369b4693f500cd98188313'
EXCHANGE_RATE_API_KEY='6c9a453dde30336217525dad'
1 change: 0 additions & 1 deletion .github/workflows/preview-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
types: [opened, reopened, synchronize]
branches-ignore:
- main
- staging

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
Expand Down
15 changes: 12 additions & 3 deletions apps/back-office/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { type AppNavLayoutProps } from '@features/appNav/ui';
import { AuthProvider, NextAuthProvider } from '@next/auth';
import { getMessages, locales } from '@next/i18n';
import { ReactQueryProviders } from '@next/react-query';
import { UploaderProvider } from '@next/uploader-provider';
import { Toaster } from '@ui/components';
import { cn } from '@ui/shared';
import { ThemeProvider } from '@ui/theme';
import { Analytics } from '@web/components/Analytics';
import { Analytics } from '@back-office/components/Analytics';
import { siteConfig } from '@back-office/config/site';
import { Metadata } from 'next';
import { createTranslator } from 'next-intl';
import { Inter as FontSans } from 'next/font/google';
import localFont from 'next/font/local';
Expand All @@ -24,16 +25,24 @@ const fontHeading = localFont({
variable: '--font-heading',
});

export const metadata: Metadata = {
title: {
default: siteConfig.name,
template: `%s - ${siteConfig.name}`,
},
};

// Error: Usage of next-intl APIs in Server Components is currently only available for dynamic rendering (i.e. no `generateStaticParams`).
// Support for static rendering is under consideration, please refer to the roadmap: https://next-intl-docs.vercel.app/docs/getting-started/app-router-server-components#roadmap
// export async function generateStaticParams() {
// return locales.map((locale) => ({ locale }));
// }

interface RootLayoutProps extends AppNavLayoutProps {
interface RootLayoutProps {
params: {
locale: string;
};
children: React.ReactNode;
}

// export async function generateStaticParams() {
Expand Down
1 change: 0 additions & 1 deletion apps/back-office/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ const nextConfig = {
// If use with serverActions is desired
serverActions: true,
useDeploymentIdServerActions: true,
appDir: true,
typedRoutes: false, // no solution found to get it working with nx monorepo (not accessible from external libs like feature)
},
sentry: {
Expand Down
3 changes: 3 additions & 0 deletions apps/web/.storybook/env-nextjs.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
createEnv: (env) => env.runtimeEnv,
};
4 changes: 4 additions & 0 deletions apps/web/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ module.exports = {
test: /\.svg$/,
use: ['@svgr/webpack', 'url-loader'],
});
config.resolve.alias['@t3-oss/env-nextjs'] = path.resolve(
__dirname,
'./env-nextjs.mock.js'
);
//
// Add tsconfig-paths-webpack-plugin to the resolve.plugins array
config.resolve.plugins = [
Expand Down
16 changes: 11 additions & 5 deletions apps/web/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import '../styles/globals.css';
import { Preview, Decorator } from '@storybook/react';
import { useEffect, useState } from 'react';
import { parameters } from '../../../storybook.preview.base';
import { NextIntlClientProvider } from 'next-intl';
import { CurrencyProvider } from '@next/currency';
import { defaultLocale } from '@next/i18n';
import { Decorator, Preview } from '@storybook/react';
import { NextIntlClientProvider } from 'next-intl';
import { useEffect, useState } from 'react';
import messagesEn from '../../../libs/next/i18n/src/messages/en.json';
import messagesfr from '../../../libs/next/i18n/src/messages/fr.json';
import { parameters } from '../../../storybook.preview.base';
import '../styles/globals.css';

window.STORYBOOK_ENV = true;

Expand Down Expand Up @@ -68,6 +69,10 @@ const I18nextStoryDecorator: Decorator = (Story, context) => {
);
};

const CurrencyDecorator: Decorator = (Story, context) => {
return <CurrencyProvider>{Story(context)}</CurrencyProvider>;
};

document.body.classList.add('font-sans');

const preview: Preview = {
Expand All @@ -81,6 +86,7 @@ const preview: Preview = {
DarkModeDecorator,
I18nextStoryDecorator,
localStorageResetDecorator,
CurrencyDecorator,
],
};
export default preview;
7 changes: 5 additions & 2 deletions apps/web/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AuthProvider, NextAuthProvider } from '@next/auth';
import { CurrencyProvider } from '@next/currency';
import { getMessages, locales } from '@next/i18n';
import { ReactQueryProviders } from '@next/react-query';
import { Toaster } from '@ui/components';
Expand Down Expand Up @@ -129,8 +130,10 @@ export default async function RootLayout({
}}
>
<ReactQueryProviders>
<AppNavLayout {...appNavLayout}>{children}</AppNavLayout>
<Toaster />
<CurrencyProvider>
<AppNavLayout {...appNavLayout}>{children}</AppNavLayout>
<Toaster />
</CurrencyProvider>
</ReactQueryProviders>
</AuthProvider>
</NextAuthProvider>
Expand Down
27 changes: 27 additions & 0 deletions apps/web/app/api/currency/rates/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getRates } from '@next/currency-cache';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest) {
try {
const rates = await getRates();

return new NextResponse(JSON.stringify(rates), {
status: 200,
headers: {
'content-type': 'application/json',
},
});
} catch (error) {
console.error(error);

return new NextResponse(
JSON.stringify({ error: 'Failed to fetch rates' }),
{
status: 500,
headers: {
'content-type': 'application/json',
},
}
);
}
}
6 changes: 1 addition & 5 deletions apps/web/sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
import * as Sentry from '@sentry/nextjs';

import env from '@env/client';
import envServer from '@env/server';

//
const SENTRY_DSN = envServer.SENTRY_AUTH_TOKEN
? null
: envServer.SENTRY_DSN || env.NEXT_PUBLIC_SENTRY_DSN;
const SENTRY_DSN = env.NEXT_PUBLIC_SENTRY_DSN;

Sentry.init({
environment: process.env.NEXT_PUBLIC_VERCEL_ENV || 'development',
Expand Down
16 changes: 16 additions & 0 deletions jest.preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ module.exports = {
},
},
],
// avoid issue with import.meta
'^.+\\.[tj]s$': [
'ts-jest',
{
diagnostics: {
ignoreCodes: [1343],
},
astTransformers: {
before: [
{
path: 'ts-jest-mock-import-meta', // or 'node_modules/ts-jest-mock-import-meta'
},
],
},
},
],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'mjs'],
coverageThreshold: {
Expand Down
18 changes: 18 additions & 0 deletions libs/currency/api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions libs/currency/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# currency-api

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build currency-api` to build the library.

## Running unit tests

Run `nx test currency-api` to execute the unit tests via [Jest](https://jestjs.io).
8 changes: 8 additions & 0 deletions libs/currency/api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable */
export default {
displayName: 'currency-api',
preset: '../../../jest.preset.js',
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/libs/currency/api',
};
10 changes: 10 additions & 0 deletions libs/currency/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@currency/api",
"version": "0.0.1",
"dependencies": {
"tslib": "^2.3.0"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts"
}
43 changes: 43 additions & 0 deletions libs/currency/api/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "currency-api",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/currency/api/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/currency/api",
"main": "libs/currency/api/src/index.ts",
"tsConfig": "libs/currency/api/tsconfig.lib.json",
"assets": ["libs/currency/api/*.md"]
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"libs/currency/api/**/*.ts",
"libs/currency/api/package.json"
]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/currency/api/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
}
},
"tags": []
}
Loading

0 comments on commit 1a9ff58

Please sign in to comment.