diff --git a/client/package.json b/client/package.json index 5181da1..6437771 100644 --- a/client/package.json +++ b/client/package.json @@ -9,6 +9,7 @@ "preview": "vite preview" }, "dependencies": { + "@tanstack/react-query": "^4.2.3", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.3.0" diff --git a/client/pnpm-lock.yaml b/client/pnpm-lock.yaml index c6b1da8..8ef6eeb 100644 --- a/client/pnpm-lock.yaml +++ b/client/pnpm-lock.yaml @@ -1,6 +1,7 @@ lockfileVersion: 5.4 specifiers: + '@tanstack/react-query': ^4.2.3 '@types/react': ^18.0.17 '@types/react-dom': ^18.0.6 '@vitejs/plugin-react': ^2.0.1 @@ -15,6 +16,7 @@ specifiers: vite: ^3.0.7 dependencies: + '@tanstack/react-query': 4.2.3_biqbaboplfbrettd7655fr4n2y react: 18.2.0 react-dom: 18.2.0_react@18.2.0 react-router-dom: 6.3.0_biqbaboplfbrettd7655fr4n2y @@ -374,6 +376,29 @@ packages: fastq: 1.13.0 dev: true + /@tanstack/query-core/4.2.3: + resolution: {integrity: sha512-zdt5lYWs1dZaA3IxJbCgtAfHZJScRZONpiLL7YkeOkrme5MfjQqTpjq7LYbzpyuwPOh2Jx68le0PLl57JFv5hQ==} + dev: false + + /@tanstack/react-query/4.2.3_biqbaboplfbrettd7655fr4n2y: + resolution: {integrity: sha512-JLaMOxoJTkiAu7QpevRCt2uI/0vd3E8K/rSlCuRgWlcW5DeJDFpDS5kfzmLO5MOcD97fgsJRrDbxDORxR1FdJA==} + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-native: '*' + peerDependenciesMeta: + react-dom: + optional: true + react-native: + optional: true + dependencies: + '@tanstack/query-core': 4.2.3 + '@types/use-sync-external-store': 0.0.3 + react: 18.2.0 + react-dom: 18.2.0_react@18.2.0 + use-sync-external-store: 1.2.0_react@18.2.0 + dev: false + /@types/prop-types/15.7.5: resolution: {integrity: sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==} dev: true @@ -396,6 +421,10 @@ packages: resolution: {integrity: sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==} dev: true + /@types/use-sync-external-store/0.0.3: + resolution: {integrity: sha512-EwmlvuaxPNej9+T4v5AuBPJa2x2UOJVdjCtDHgcDqitUeOtjnJKJ+apYjVcAoBEMjKW1VVFGZLUb5+qqa09XFA==} + dev: false + /@vitejs/plugin-react/2.0.1_vite@3.0.7: resolution: {integrity: sha512-uINzNHmjrbunlFtyVkST6lY1ewSfz/XwLufG0PIqvLGnpk2nOIOa/1CACTDNcKi1/RwaCzJLmsXwm1NsUVV/NA==} engines: {node: ^14.18.0 || >=16.0.0} @@ -1298,6 +1327,14 @@ packages: picocolors: 1.0.0 dev: true + /use-sync-external-store/1.2.0_react@18.2.0: + resolution: {integrity: sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==} + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + dependencies: + react: 18.2.0 + dev: false + /util-deprecate/1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} dev: true diff --git a/client/src/App.tsx b/client/src/App.tsx index c99c399..be6d60b 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,9 +1,13 @@ -import { Outlet } from "react-router-dom"; +import { Outlet } from 'react-router-dom'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; + +// Create a client +const queryClient = new QueryClient(); export default () => { return ( - <> + - + ); -} +}; diff --git a/client/src/routes/login.tsx b/client/src/routes/login.tsx index 31fc3f5..d01e624 100644 --- a/client/src/routes/login.tsx +++ b/client/src/routes/login.tsx @@ -1,8 +1,23 @@ import { Link } from 'react-router-dom'; - import logo from '@assets/images/logo.svg'; +import { useQuery, useMutation, useQueryClient, QueryClient, QueryClientProvider } from '@tanstack/react-query'; export default () => { + // Access the client + const queryClient = useQueryClient(); + + const mutation = useMutation(formData => { + return fetch('/api/auth/login', { + method: 'POST', + body: formData, + }); + }) + const onSubmit = event => { + event.preventDefault() + const formData = new FormData(event.target) + mutation.mutate({email: formData.get('email'), password: formData.get('password')}) + } + return ( <>
@@ -10,14 +25,14 @@ export default () => { Groupomania
-
+
-