From 27b24a22a76664a8eb5cc71da595d38512191d51 Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Sun, 17 Mar 2024 03:57:38 -0400 Subject: [PATCH] feat: activate page (#6) --- src/client/index.ts | 96 +++++++++++++++++++++++++++++++++++- src/pages/Activate/index.tsx | 39 +++++++++++++++ src/routes.tsx | 5 ++ 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/pages/Activate/index.tsx diff --git a/src/client/index.ts b/src/client/index.ts index 2fc957e..eaaf27e 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -80,6 +80,52 @@ export interface SchemaMovieListResponse { offset?: number } +export interface SchemaRegisterUser { + /** @maxLength 150 */ + address: string + /** @maxLength 150 */ + address2?: string + /** @maxLength 150 */ + cardAddress?: string + /** @maxLength 150 */ + cardAddress2?: string + /** @maxLength 100 */ + cardCity?: string + /** @maxLength 50 */ + cardExpiration?: string + /** @maxLength 50 */ + cardNumber?: string + /** @maxLength 100 */ + cardState?: string + /** @maxLength 50 */ + cardType?: string + /** @maxLength 20 */ + cardZip?: string + /** @maxLength 100 */ + city: string + /** @maxLength 150 */ + email: string + /** @maxLength 100 */ + name: string + needPromotion?: boolean + /** + * @minLength 8 + * @maxLength 100 + */ + password: string + /** @maxLength 20 */ + phone: string + /** @maxLength 100 */ + state: string + /** + * @minLength 3 + * @maxLength 50 + */ + userName: string + /** @maxLength 20 */ + zip: string +} + export interface SchemaTokenResponse { access_token?: string msg?: string @@ -122,11 +168,10 @@ export interface SchemaUpsertMovie { export interface SchemaUser { created_at?: string email?: string - first_name?: string id: string is_active?: boolean is_admin?: boolean - last_name?: string + name?: string updated_at?: string username?: string } @@ -512,6 +557,32 @@ export class Api< }) } auth = { + /** + * @description Activate a new user. + * + * @tags Auth + * @name V1AuthActivateCreate + * @summary activate + * @request POST:/api/v1/auth/activate + */ + v1AuthActivateCreate: ( + query?: { + /** id */ + id?: string + /** code */ + code?: string + }, + params: RequestParams = {} + ) => + this.request({ + path: `/api/v1/auth/activate`, + method: 'POST', + query: query, + type: ContentType.Json, + format: 'json', + ...params + }), + /** * @description Get current JWT. * @@ -574,6 +645,27 @@ export class Api< type: ContentType.Json, format: 'json', ...params + }), + + /** + * @description Register for a new user. + * + * @tags Auth + * @name V1AuthRegisterCreate + * @summary register + * @request POST:/api/v1/auth/register + */ + v1AuthRegisterCreate: ( + register: SchemaRegisterUser, + params: RequestParams = {} + ) => + this.request({ + path: `/api/v1/auth/register`, + method: 'POST', + body: register, + type: ContentType.Json, + format: 'json', + ...params }) } movie = { diff --git a/src/pages/Activate/index.tsx b/src/pages/Activate/index.tsx new file mode 100644 index 0000000..5147d45 --- /dev/null +++ b/src/pages/Activate/index.tsx @@ -0,0 +1,39 @@ +import { useRequest } from 'ahooks' +import PageContainer from 'components/PageContainer' +import { useNavigate, useSearchParams } from 'react-router-dom' +import Backend from 'utils/service' + +const Activate: React.FC = () => { + const navigate = useNavigate() + const [searchParams] = useSearchParams() + const id = searchParams.get('id') ?? '' + const code = searchParams.get('code') ?? '' + const { loading } = useRequest( + async () => + Backend.auth.v1AuthActivateCreate({ + id, + code + }), + { + onSuccess: () => { + navigate('/') + }, + onError: () => { + navigate('/register') + } + } + ) + return ( +
+

{loading ? 'Loading' : 'Redirecting'}

+
+ ) +} + +const Index: React.FC = () => ( + + + +) + +export default Index diff --git a/src/routes.tsx b/src/routes.tsx index 0808ed7..72c7305 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -1,4 +1,5 @@ // import { ProtectedRoute } from 'components/ProtectedRoute' +import Activate from 'pages/Activate' import Checkout from 'pages/Checkout' import EditProfile from 'pages/EditProfile' import Login from 'pages/Login' @@ -29,6 +30,10 @@ const children: RouteObject[] = [ path: '/register', element: }, + { + path: '/activate', + element: + }, { path: '/profile/edit', element: