Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

feat: generate api #465

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ cypress/downloads/
!.yarn/releases
!.yarn/sdks
!.yarn/versions

tmp

# api generation
src/client
openapi-ts-error-*
20 changes: 20 additions & 0 deletions openapi-ts.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
client: '@hey-api/client-fetch',
// TODO: provide api.graasp.org/docs/json , here we can change the link given .env.development
input: './tmp/openapi.json',
output: {
format: 'prettier',
lint: 'eslint',
path: './src/client',
},
schemas: {
type: 'json',
},
plugins: ['@tanstack/react-query'],
types: {
dates: 'types+transform',
enums: 'javascript',
},
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@mui/lab": "5.0.0-alpha.170",
"@mui/material": "5.16.7",
"@sentry/react": "7.119.0",
"@tanstack/react-query": "5.59.0",
"date-fns": "4.1.0",
"http-status-codes": "2.3.0",
"i18next": "23.15.1",
Expand Down Expand Up @@ -85,6 +86,8 @@
"@commitlint/cli": "19.5.0",
"@commitlint/config-conventional": "19.5.0",
"@cypress/code-coverage": "3.13.4",
"@hey-api/client-fetch": "0.4.0",
"@hey-api/openapi-ts": "0.53.7",
"@testing-library/jest-dom": "6.5.0",
"@testing-library/react": "16.0.1",
"@testing-library/user-event": "14.5.2",
Expand Down
12 changes: 8 additions & 4 deletions src/components/signIn/MagicLinkForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMutation } from '@tanstack/react-query';
import React, { useState } from 'react';
import { useNavigate } from 'react-router';

Expand All @@ -6,6 +7,7 @@ import { RecaptchaAction } from '@graasp/sdk';
import { LoadingButton } from '@mui/lab';
import { Stack } from '@mui/material';

import { postLoginMutation } from '../../client/@tanstack/react-query.gen';
import { useAuthTranslation } from '../../config/i18n';
import { SIGN_IN_MAGIC_LINK_SUCCESS_PATH } from '../../config/paths';
import { mutations } from '../../config/queryClient';
Expand Down Expand Up @@ -40,7 +42,7 @@ const MagicLinkForm = () => {
mutateAsync: signIn,
isPending: isLoadingSignIn,
error: webSignInError,
} = mutations.useSignIn();
} = useMutation(postLoginMutation());
const {
mutateAsync: mobileSignIn,
isPending: isLoadingMobileSignIn,
Expand All @@ -62,9 +64,11 @@ const MagicLinkForm = () => {
await (isMobile
? mobileSignIn({ email: lowercaseEmail, captcha: token, challenge })
: signIn({
email: lowercaseEmail,
captcha: token,
url: redirect.url,
body: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to encapsulate in body, I think it's good as it is clear why the props are used.

email: lowercaseEmail,
captcha: token,
url: redirect.url,
},
}));

// navigate to success path
Expand Down
Loading
Loading