-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: manage otp bypass tokens * fix: count tokens * merge from main * new cfl package * fix: new cfl package * feedback
- Loading branch information
Showing
12 changed files
with
269 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,46 @@ | ||
import { urls } from "codeforlife/api" | ||
import { type ListArg, type ListResult, listTag } from "codeforlife/utils/api" | ||
import { type OtpBypassToken, urls } from "codeforlife/api" | ||
|
||
import api from "." | ||
|
||
export type GenerateOtpBypassTokensResult = string[] | ||
export type ListOtpBypassTokensResult = ListResult< | ||
OtpBypassToken, | ||
never, | ||
{ decrypted_token: string } | ||
> | ||
export type ListOtpBypassTokensArg = ListArg | ||
|
||
export type GenerateOtpBypassTokensResult = ListOtpBypassTokensResult["data"] | ||
export type GenerateOtpBypassTokensArg = null | ||
|
||
const otpBypassTokenApi = api.injectEndpoints({ | ||
endpoints: build => ({ | ||
listOtpBypassTokens: build.query< | ||
ListOtpBypassTokensResult, | ||
ListOtpBypassTokensArg | ||
>({ | ||
query: () => ({ | ||
url: urls.otpBypassToken.list, | ||
method: "GET", | ||
}), | ||
providesTags: [listTag("OtpBypassToken")], | ||
}), | ||
generateOtpBypassTokens: build.mutation< | ||
GenerateOtpBypassTokensResult, | ||
GenerateOtpBypassTokensArg | ||
>({ | ||
query: () => ({ | ||
url: urls.otpBypassToken.list, | ||
url: urls.otpBypassToken.list + "generate/", | ||
method: "POST", | ||
}), | ||
invalidatesTags: [listTag("OtpBypassToken")], | ||
}), | ||
}), | ||
}) | ||
|
||
export default otpBypassTokenApi | ||
export const { useGenerateOtpBypassTokensMutation } = otpBypassTokenApi | ||
export const { | ||
useLazyListOtpBypassTokensQuery, | ||
useListOtpBypassTokensQuery, | ||
useGenerateOtpBypassTokensMutation, | ||
} = otpBypassTokenApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 38 additions & 6 deletions
44
src/pages/teacherDashboard/account/otpBypassTokens/OtpBypassTokens.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,45 @@ | ||
import * as pages from "codeforlife/components/page" | ||
import { type FC } from "react" | ||
import { type RetrieveUserResult } from "../../../../api/user" | ||
import { type SchoolTeacherUser } from "codeforlife/api" | ||
import { Navigate } from "codeforlife/components/router" | ||
import { type User } from "codeforlife/api" | ||
import { handleResultState } from "codeforlife/utils/api" | ||
|
||
import OtpExists from "./OtpExists" | ||
import { paths } from "../../../../routes" | ||
import { useListAuthFactorsQuery } from "../../../../api/authFactor" | ||
|
||
export interface OtpBypassTokensProps { | ||
authUser: SchoolTeacherUser<RetrieveUserResult> | ||
authUserId: User["id"] | ||
} | ||
|
||
const OtpBypassTokens: FC<OtpBypassTokensProps> = () => { | ||
return <>TODO</> | ||
} | ||
const OtpBypassTokens: FC<OtpBypassTokensProps> = ({ authUserId }) => ( | ||
<pages.Section> | ||
{handleResultState( | ||
useListAuthFactorsQuery( | ||
{ offset: 0, limit: 0, user: authUserId, type: "otp" }, | ||
{ refetchOnMountOrArgChange: true }, | ||
), | ||
({ count: exists }) => | ||
exists ? ( | ||
<OtpExists /> | ||
) : ( | ||
<Navigate | ||
to={paths.teacher.dashboard.tab.account.otp.setup._} | ||
replace | ||
state={{ | ||
notifications: [ | ||
{ | ||
props: { | ||
error: true, | ||
children: "One-time password not set up.", | ||
}, | ||
}, | ||
], | ||
}} | ||
/> | ||
), | ||
)} | ||
</pages.Section> | ||
) | ||
|
||
export default OtpBypassTokens |
Oops, something went wrong.