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

Commit

Permalink
feat: activate page (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoYanZh authored Mar 17, 2024
1 parent 0d48f98 commit 27b24a2
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 2 deletions.
96 changes: 94 additions & 2 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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<SchemaUser, SchemaErrorResponse>({
path: `/api/v1/auth/activate`,
method: 'POST',
query: query,
type: ContentType.Json,
format: 'json',
...params
}),

/**
* @description Get current JWT.
*
Expand Down Expand Up @@ -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<SchemaUser, SchemaErrorResponse>({
path: `/api/v1/auth/register`,
method: 'POST',
body: register,
type: ContentType.Json,
format: 'json',
...params
})
}
movie = {
Expand Down
39 changes: 39 additions & 0 deletions src/pages/Activate/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className='text-center'>
<h1>{loading ? 'Loading' : 'Redirecting'}</h1>
</div>
)
}

const Index: React.FC = () => (
<PageContainer>
<Activate />
</PageContainer>
)

export default Index
5 changes: 5 additions & 0 deletions src/routes.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -29,6 +30,10 @@ const children: RouteObject[] = [
path: '/register',
element: <Register />
},
{
path: '/activate',
element: <Activate />
},
{
path: '/profile/edit',
element: <EditProfile />
Expand Down

0 comments on commit 27b24a2

Please sign in to comment.