Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
218 commits
Select commit Hold shift + click to select a range
e5205ce
Fix breadcrumb colors
sean-brydon Jul 25, 2022
f2f075f
HorizontalTabs
sean-brydon Jul 25, 2022
dbd657c
Team List Item WIP
sean-brydon Jul 25, 2022
8fe290a
Merge remote-tracking branch 'origin/main' into V2-Components
sean-brydon Jul 26, 2022
1b6cb6b
Horizontal Tabs
sean-brydon Jul 26, 2022
104cd2e
Cards
sean-brydon Jul 26, 2022
193dd03
Remove team list item WIP
sean-brydon Jul 26, 2022
a0db67e
Merge branch 'main' into V2-Components
sean-brydon Jul 26, 2022
6677490
Login Page
sean-brydon Jul 26, 2022
02ab411
Add welcome back i118n
sean-brydon Jul 26, 2022
72c800d
EventType page work
sean-brydon Jul 26, 2022
8c81fcc
Update EventType Icons
sean-brydon Jul 26, 2022
79ff480
WIP Availability
sean-brydon Jul 27, 2022
c829830
Merge branch 'V2-Components' into feat/V2.0
sean-brydon Jul 27, 2022
b32ba65
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Jul 27, 2022
12d8f20
Horizontal Tab Work
sean-brydon Jul 27, 2022
b232ad8
Merge branch 'main' into feat/V2.0
sean-brydon Jul 27, 2022
b3935d5
Add build command for in root
sean-brydon Jul 27, 2022
a72671b
Update build DIr/command
sean-brydon Jul 27, 2022
d0ad652
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Jul 27, 2022
011db77
Add Edit Button + change buttons to v2
sean-brydon Jul 27, 2022
d78a53a
Availablitiy page
sean-brydon Jul 27, 2022
98f25d6
Fix IPAD
sean-brydon Jul 27, 2022
260d793
Make mobile look a little nicer
sean-brydon Jul 27, 2022
ac5837f
WIP bookingshell
sean-brydon Jul 27, 2022
c2228e4
Merge branch 'main' into feat/V2.0
sean-brydon Jul 27, 2022
28f1b25
Merge branch 'feat/V2.0' of https://github.com/calcom/cal.com into fe…
sean-brydon Jul 28, 2022
48ac5ec
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Jul 28, 2022
fff167d
Remove list items from breaking build
sean-brydon Jul 28, 2022
135c34c
Mian bulk of Booking Page.
sean-brydon Jul 28, 2022
70d40a3
Few updates to components
sean-brydon Jul 29, 2022
e6bbcbe
Fix chormatic feedback
sean-brydon Jul 29, 2022
d04798f
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Aug 1, 2022
4f620f7
Fix banner
sean-brydon Aug 1, 2022
ee3aa72
Fix Empty Screen
sean-brydon Aug 1, 2022
9fb83bb
Text area + embded window fixes
sean-brydon Aug 1, 2022
a0c7a67
Semi fix avatar
sean-brydon Aug 1, 2022
dee1e4e
Troubleshoot container + Active on count
sean-brydon Aug 1, 2022
131b6b4
Merge branch 'main' into feat/V2.0
PeerRich Aug 1, 2022
b9cb152
Improve mobile
sean-brydon Aug 2, 2022
c906830
NITS
sean-brydon Aug 2, 2022
a1667fd
Fix padding on input
sean-brydon Aug 2, 2022
02c3e51
Merge branch 'feat/V2.0' of https://github.com/calcom/cal.com into fe…
sean-brydon Aug 2, 2022
0fb768f
Fix icons
sean-brydon Aug 2, 2022
bac4dac
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Aug 4, 2022
a2e5a73
Starting to move event types settings to tabs
sean-brydon Aug 4, 2022
b608b65
Begin migration to single page form
sean-brydon Aug 5, 2022
d2d82ea
Single page tabs
sean-brydon Aug 5, 2022
c8defae
Limits Page
sean-brydon Aug 6, 2022
3e3a2ea
Advanced tab
sean-brydon Aug 7, 2022
a534451
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Aug 7, 2022
f214528
Add RHF to dependancies
sean-brydon Aug 7, 2022
784614f
Merge branch 'main' of https://github.com/calcom/cal.com into feat/V2.0
sean-brydon Aug 8, 2022
b251b75
Most of advanced tab
sean-brydon Aug 8, 2022
1be9a22
Merge branch 'main' of https://github.com/calcom/cal.com into feat/V2.0
sean-brydon Aug 8, 2022
e32adb4
Solved RHF mismtach
zomars Aug 8, 2022
867e9cb
Build fixes
zomars Aug 8, 2022
6e0b844
Merge branch 'main' into feat/V2.0
zomars Aug 8, 2022
8a179a1
RHF conditionals fixes
zomars Aug 8, 2022
077e795
Improved legibility
zomars Aug 8, 2022
b9ddc90
Merge branch 'feat/V2.0' of https://github.com/calcom/cal.com into fe…
sean-brydon Aug 9, 2022
8f9e5f3
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Aug 9, 2022
f264b41
Major refactor/organisation into optional V2 UI
sean-brydon Aug 10, 2022
fb9260f
Portal EditLocationModal
sean-brydon Aug 10, 2022
4795159
Fix dialoug form
sean-brydon Aug 10, 2022
033ffde
Update imports
sean-brydon Aug 10, 2022
e147c75
Auto Animate + custom inputs WIP
sean-brydon Aug 11, 2022
828d661
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Aug 11, 2022
5049e63
Custom Inputs
sean-brydon Aug 11, 2022
4d336c8
WIP Apps
sean-brydon Aug 11, 2022
12c3372
Fixing stories imports
sean-brydon Aug 12, 2022
e2a55d4
Stripe app
sean-brydon Aug 12, 2022
a9ca2b9
Remove duplicate dialog
sean-brydon Aug 12, 2022
5d478c3
Remove duplicate dialog
sean-brydon Aug 12, 2022
5748eb5
Merge branch 'feat/V2.0' of https://github.com/calcom/cal.com into fe…
sean-brydon Aug 12, 2022
e9213c5
Merge branch 'feat/V2.0' of https://github.com/calcom/cal.com into fe…
sean-brydon Aug 12, 2022
d7b83a4
Merge branch 'feat/V2.0' of https://github.com/calcom/cal.com into fe…
sean-brydon Aug 12, 2022
a2e838c
add Test action button + UI improvements
Aug 12, 2022
f0da8c9
Merge branch 'main' into feat/test-workflow-button
Aug 13, 2022
36984e9
add test action functionality
Aug 13, 2022
a73b9b9
Merge remote-tracking branch 'origin/main' into feat/v2.0
hariombalhara Aug 13, 2022
3f33afa
Merge remote-tracking branch 'origin/main' into feat/V2.0
hariombalhara Aug 13, 2022
0973830
Merge branch 'main' into feat/V2.0
sean-brydon Aug 15, 2022
4246300
Fix embed URL
sean-brydon Aug 15, 2022
a703f9a
Fix app toggles + number of active apps
sean-brydon Aug 15, 2022
c0deb23
Fix container padding on disabledBorder prop
sean-brydon Aug 15, 2022
0d5b432
Removes strict
sean-brydon Aug 15, 2022
8d4164b
add confirmation dialog before sending SMS
Aug 15, 2022
451e33c
code clean up
Aug 15, 2022
1602b46
Merge branch 'main' into feat/test-workflow-button
Aug 15, 2022
22f1a4d
show error message if test action fails
Aug 15, 2022
78bad11
disable test action button in edit mode
Aug 15, 2022
6343800
fixes SMS testing
Aug 16, 2022
6464c27
use updated values
Aug 16, 2022
d68871d
fix wrongly updated data in useEffect
Aug 16, 2022
4a519be
fix typo
Aug 16, 2022
d4a18d4
code clean up
Aug 16, 2022
1d4c4cf
EventType Team page WIP
sean-brydon Aug 16, 2022
e9e417e
Fix embed
hariombalhara Aug 16, 2022
ebcdeba
Merge remote-tracking branch 'origin/feat/V2.0' into feat/V2.0
hariombalhara Aug 16, 2022
6963070
NIT
sean-brydon Aug 16, 2022
e869f30
Add Darkmode gray color
sean-brydon Aug 16, 2022
8d387b9
Merge branch 'feat/V2.0' of https://github.com/calcom/cal.com into fe…
sean-brydon Aug 16, 2022
850e5a6
V2 Shell WIP
sean-brydon Aug 16, 2022
14c4ebf
Merge branch 'feat/test-workflow-button' into feat/v2-workflows
Aug 16, 2022
c905963
setup folders for v2
Aug 16, 2022
965e304
add lost translations from merge
Aug 17, 2022
ce43801
add all files to v2 + redesign /workflows
Aug 17, 2022
9484a80
use custom template as default template
Aug 17, 2022
dd6934b
add first version of v2 for workflow editing page
Aug 17, 2022
53f9015
Fix headings on shell V2
sean-brydon Aug 17, 2022
efd1b04
Fix mobile layout with V2 shell
sean-brydon Aug 17, 2022
85b1fb3
V2 create event type button
sean-brydon Aug 17, 2022
1cf5f59
Checked Team Select
sean-brydon Aug 17, 2022
fccfa7d
Hidden to happen on save - not on toggle
sean-brydon Aug 17, 2022
9b1a825
Team Attendee Select animation
sean-brydon Aug 17, 2022
5a36747
Fix scheduling type and remove multi select label
sean-brydon Aug 17, 2022
7ba1a07
Fix overflow on teams url
sean-brydon Aug 17, 2022
0dac841
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Aug 17, 2022
986e7f3
use fi icon for down arrow
Aug 17, 2022
dc2b5b1
Merge branch 'feat/V2.0' into feat/v2-workflows
Aug 17, 2022
9b51c19
add v2 shell
Aug 17, 2022
a655c6a
add trigger badge
Aug 17, 2022
8facf32
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Aug 18, 2022
14f2e5f
Even Type move order handles
sean-brydon Aug 18, 2022
044bcf4
Merge branch 'feat/V2.0' into feat/v2-workflows
Aug 18, 2022
18c9e99
fix save button
Aug 18, 2022
4c53f4e
enable editing of workflow name
Aug 18, 2022
7d3f77c
improve delete workflow functionality
Aug 18, 2022
843488d
adjust empty screen
Aug 18, 2022
f1b07ac
make trigger start with uppercase
Aug 19, 2022
fd35a9f
change trash icon
Aug 19, 2022
622bdda
Merge remote-tracking branch 'origin' into feat/V2.0
hariombalhara Aug 19, 2022
b7a0cfa
Fix Embed TS errors
hariombalhara Aug 19, 2022
5e9009f
Fix TS errors
hariombalhara Aug 19, 2022
93ea059
Fix Eslint errors
hariombalhara Aug 19, 2022
004a8c3
Fix TS errors for UI
hariombalhara Aug 19, 2022
e6af740
Fix ESLINT error
hariombalhara Aug 19, 2022
7876ed5
create component for time and timeUnit input/dropdown
Aug 19, 2022
5e5aa9e
Merge branch 'feat/V2.0' into feat/v2-workflows
Aug 19, 2022
2c01603
add workflows to v2 early access middleware
Aug 19, 2022
dbdafad
fix type issues
Aug 19, 2022
dbf7f84
Merge branch 'feat/V2.0' of https://github.com/calcom/cal.com into fe…
sean-brydon Aug 21, 2022
63bb6b6
added SidebarCard for promo to v2 and storybook (#3906)
PeerRich Aug 21, 2022
1c3d354
Tooltip Provider - Wrapper due to dep upgrade
sean-brydon Aug 21, 2022
7e007fa
public event type list darkmode
sean-brydon Aug 22, 2022
a8347c3
V2 Color changes to public booking
sean-brydon Aug 22, 2022
7fbc4f8
Merge branch 'feat/V2.0' into feat/v2-workflows
Aug 22, 2022
96faaab
adjust delete and edit button
Aug 22, 2022
3ebba04
create custom empty screen for worklows
Aug 22, 2022
7efeb0a
add workflow examples to empty page
Aug 22, 2022
4e1e54a
add loading state to button when creating first workflow
Aug 22, 2022
db393d0
Show action as workflow name when no name exists
Aug 22, 2022
9d72335
if no input leave name empty when updating workflow
Aug 22, 2022
5240c07
use reminder template when creating workflow
Aug 22, 2022
2a66dbf
improve time unit dropdown
Aug 22, 2022
a723ad1
Merge remote-tracking branch 'origin/main' into feat/V2.0
sean-brydon Aug 23, 2022
e86a104
Remove unused component
sean-brydon Aug 23, 2022
893a3f1
Fix typecheck
sean-brydon Aug 23, 2022
60ba462
Merge branch 'feat/V2.0' of https://github.com/calcom/cal.com into fe…
sean-brydon Aug 23, 2022
7c5cc7a
Merge branch 'feat/V2.0' into feat/v2-workflows
Aug 23, 2022
dcba04e
add loading state to new workflow button
Aug 23, 2022
7974206
add label before action dropdown
Aug 23, 2022
22499ec
fixing badges in worflow list
Aug 23, 2022
1703b27
use lighter color for untitled workflows
Aug 23, 2022
7ad1001
fix not showing nr of active eventtypes in workflow list
Aug 23, 2022
6270216
add workflows to event types
Aug 24, 2022
dc0e254
implement v2 desing for AddActionDialog
Aug 24, 2022
b5a2473
improve phone input
Aug 24, 2022
92521b0
rounded borders for phoneInput in add action dialog
Aug 24, 2022
431fbcc
improve message input
Aug 25, 2022
e49d105
Merge branch 'main' into feat/v2-workflows
Aug 25, 2022
6052785
Merge branch 'main' into feat/v2-workflows
Aug 25, 2022
85959bb
fix mobile view for editing page
Aug 25, 2022
49d32d9
use md breakpoint for mobile view
Aug 25, 2022
7d53415
finish workflows in event type settings
Aug 26, 2022
87aea69
Merge branch 'main' into feat/v2-workflows
Aug 26, 2022
095c119
code cleanup
Aug 26, 2022
d3e81dc
code cleanup
Aug 26, 2022
e4498fb
Merge branch 'main' into feat/v2-workflows
Aug 26, 2022
7e5a2a8
fix bug in testing workflow action
Aug 26, 2022
bb1ea86
add v2 design for addition inputs as variables dialog
Aug 26, 2022
2c1ead2
add V2 design for add variable dropdown
Aug 27, 2022
a1705b3
add notification icons to trigger badge
Aug 27, 2022
98ea40c
improve mobile version of workflows in eventtypes
Aug 27, 2022
4c7d383
Merge branch 'main' into feat/v2-workflows
Aug 29, 2022
4203d1d
remove ring from time before input
Aug 29, 2022
4e95269
fix bug when workflow has no steps
Aug 29, 2022
9476311
Final UI improvements/fixes
Aug 30, 2022
d753223
code clean-up
Aug 30, 2022
c5094a4
code clean-up
Aug 30, 2022
511f74d
Merge branch 'main' into feat/v2-workflows
Aug 30, 2022
b020bee
code clean-up
Aug 30, 2022
ccad2b5
use v2 design for license required
Aug 30, 2022
fcd42ab
fix translation issues
Aug 30, 2022
77556c7
fix adding variables in different language in old design
Aug 30, 2022
ebc5214
limit for pro users only for now
Aug 30, 2022
9495140
Merge branch 'main' into feat/v2-workflows
Aug 30, 2022
a35d50c
Merge branch 'main' into feat/v2-workflows
kodiakhq[bot] Aug 30, 2022
779a9b2
fix import
Aug 30, 2022
0e2e0ee
Merge branch 'feat/v2-workflows' of https://github.com/calcom/cal.com…
Aug 30, 2022
76e6a9a
fix mobile view for empty screen
Aug 30, 2022
efe081c
ues destructive button color for deleting workfow
Aug 30, 2022
e3d0347
remove padding at button of creation dialog
Aug 30, 2022
2174dc0
V2 Settings - Security View (#4018)
joeauyeung Aug 30, 2022
3274fcf
fix: rate limit auth (#3820)
agustif Aug 30, 2022
2310773
Merge branch 'main' into feat/v2-workflows
zomars Aug 30, 2022
708a998
Merge branch 'main' into feat/v2-workflows
kodiakhq[bot] Aug 30, 2022
9f30c2d
Merge branch 'main' into feat/v2-workflows
kodiakhq[bot] Aug 31, 2022
63d0570
Merge branch 'main' into feat/v2-workflows
kodiakhq[bot] Aug 31, 2022
17dfd57
Merge branch 'main' into feat/v2-workflows
kodiakhq[bot] Aug 31, 2022
733b642
Merge branch 'main' into feat/v2-workflows
kodiakhq[bot] Aug 31, 2022
1dcfb73
Merge branch 'main' into feat/v2-workflows
kodiakhq[bot] Aug 31, 2022
185c62a
Merge branch 'main' into feat/v2-workflows
zomars Aug 31, 2022
a3350e1
Merge branch 'main' into feat/v2-workflows
Aug 31, 2022
a9b0b07
Merge branch 'feat/v2-workflows' of https://github.com/calcom/cal.com…
Aug 31, 2022
9312096
Merge branch 'main' into feat/v2-workflows
kodiakhq[bot] Aug 31, 2022
c6cfb3d
Adds deprecation comments
zomars Aug 31, 2022
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
Prev Previous commit
Next Next commit
V2 Settings - Security View (#4018)
* Create change password screen

* Add two factor auth screen

* Add two factor auth screen

* Remove header file

* Updates middleware and rewrites

* Adds Meta component to handle layout headings/metadata (#4021)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
  • Loading branch information
3 people committed Aug 30, 2022
commit 2174dc0289e592ef28d8534834cdcdb76e9c499b
107 changes: 107 additions & 0 deletions apps/web/components/v2/settings/DisableTwoFactorModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { SyntheticEvent, useState } from "react";

import { useLocale } from "@calcom/lib/hooks/useLocale";
import Button from "@calcom/ui/v2/core/Button";
import { Dialog, DialogContent } from "@calcom/ui/v2/core/Dialog";

import { ErrorCode } from "@lib/auth";

import TwoFactorAuthAPI from "./TwoFactorAuthAPI";

interface DisableTwoFactorAuthModalProps {
open: boolean;
onOpenChange: () => void;

/** Called when the user closes the modal without disabling two-factor auth */
onCancel: () => void;
/** Called when the user disables two-factor auth */
onDisable: () => void;
}

const DisableTwoFactorAuthModal = ({
onDisable,
onCancel,
open,
onOpenChange,
}: DisableTwoFactorAuthModalProps) => {
const [password, setPassword] = useState("");
const [isDisabling, setIsDisabling] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const { t } = useLocale();

async function handleDisable(e: SyntheticEvent) {
e.preventDefault();

if (isDisabling) {
return;
}
setIsDisabling(true);
setErrorMessage(null);

try {
const response = await TwoFactorAuthAPI.disable(password);
if (response.status === 200) {
onDisable();
return;
}

const body = await response.json();
if (body.error === ErrorCode.IncorrectPassword) {
setErrorMessage(t("incorrect_password"));
} else {
setErrorMessage(t("something_went_wrong"));
}
} catch (e) {
setErrorMessage(t("something_went_wrong"));
console.error(t("error_disabling_2fa"), e);
} finally {
setIsDisabling(false);
}
}

return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent
title={t("disable_2fa")}
description={t("disable_2fa_recommendation")}
type="creation"
useOwnActionButtons>
<form onSubmit={handleDisable}>
<div className="mb-4">
<label htmlFor="password" className="mt-4 block text-sm font-medium text-gray-700">
{t("password")}
</label>
<div className="mt-1">
<input
type="password"
name="password"
id="password"
required
value={password}
onInput={(e) => setPassword(e.currentTarget.value)}
className="block w-full rounded-sm border-gray-300 text-sm"
/>
</div>

{errorMessage && <p className="mt-1 text-sm text-red-700">{errorMessage}</p>}
</div>
</form>

<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
<Button
type="submit"
className="ltr:ml-2 rtl:mr-2"
onClick={handleDisable}
disabled={password.length === 0 || isDisabling}>
{t("disable")}
</Button>
<Button color="secondary" onClick={onCancel}>
{t("cancel")}
</Button>
</div>
</DialogContent>
</Dialog>
);
};

export default DisableTwoFactorAuthModal;
232 changes: 232 additions & 0 deletions apps/web/components/v2/settings/EnableTwoFactorModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
import React, { SyntheticEvent, useState } from "react";

import { useLocale } from "@calcom/lib/hooks/useLocale";
import Button from "@calcom/ui/v2/core/Button";
import { Dialog, DialogContent } from "@calcom/ui/v2/core/Dialog";

import { ErrorCode } from "@lib/auth";

import TwoFactorAuthAPI from "./TwoFactorAuthAPI";

interface EnableTwoFactorModalProps {
open: boolean;
onOpenChange: () => void;

/**
* Called when the user closes the modal without disabling two-factor auth
*/
onCancel: () => void;

/**
* Called when the user enables two-factor auth
*/
onEnable: () => void;
}

enum SetupStep {
ConfirmPassword,
DisplayQrCode,
EnterTotpCode,
}

const WithStep = ({
step,
current,
children,
}: {
step: SetupStep;
current: SetupStep;
children: JSX.Element;
}) => {
return step === current ? children : null;
};

const EnableTwoFactorModal = ({ onEnable, onCancel, open, onOpenChange }: EnableTwoFactorModalProps) => {
const { t } = useLocale();
const setupDescriptions = {
[SetupStep.ConfirmPassword]: t("2fa_confirm_current_password"),
[SetupStep.DisplayQrCode]: t("2fa_scan_image_or_use_code"),
[SetupStep.EnterTotpCode]: t("2fa_enter_six_digit_code"),
};
const [step, setStep] = useState(SetupStep.ConfirmPassword);
const [password, setPassword] = useState("");
const [totpCode, setTotpCode] = useState("");
const [dataUri, setDataUri] = useState("");
const [secret, setSecret] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);

async function handleSetup(e: SyntheticEvent) {
e.preventDefault();

if (isSubmitting) {
return;
}

setIsSubmitting(true);
setErrorMessage(null);

try {
const response = await TwoFactorAuthAPI.setup(password);
const body = await response.json();

if (response.status === 200) {
setDataUri(body.dataUri);
setSecret(body.secret);
setStep(SetupStep.DisplayQrCode);
return;
}

if (body.error === ErrorCode.IncorrectPassword) {
setErrorMessage(t("incorrect_password"));
} else {
setErrorMessage(t("something_went_wrong"));
}
} catch (e) {
setErrorMessage(t("something_went_wrong"));
console.error(t("error_enabling_2fa"), e);
} finally {
setIsSubmitting(false);
}
}

async function handleEnable(e: SyntheticEvent) {
e.preventDefault();

if (isSubmitting || totpCode.length !== 6) {
return;
}

setIsSubmitting(true);
setErrorMessage(null);

try {
const response = await TwoFactorAuthAPI.enable(totpCode);
const body = await response.json();

if (response.status === 200) {
onEnable();
return;
}

if (body.error === ErrorCode.IncorrectTwoFactorCode) {
setErrorMessage(`${t("code_is_incorrect")} ${t("please_try_again")}`);
} else {
setErrorMessage(t("something_went_wrong"));
}
} catch (e) {
setErrorMessage(t("something_went_wrong"));
console.error(t("error_enabling_2fa"), e);
} finally {
setIsSubmitting(false);
}
}

return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent
title={t("enable_2fa")}
description={setupDescriptions[step]}
type="creation"
useOwnActionButtons
// Icon={Icon.FiAlertTriangle}>
>
{/* <TwoFactorModalHeader title={t("enable_2fa")} description={setupDescriptions[step]} /> */}

<WithStep step={SetupStep.ConfirmPassword} current={step}>
<form onSubmit={handleSetup}>
<div className="mb-4">
<label htmlFor="password" className="mt-4 block text-sm font-medium text-gray-700">
{t("password")}
</label>
<div className="mt-1">
<input
type="password"
name="password"
id="password"
required
value={password}
onInput={(e) => setPassword(e.currentTarget.value)}
className="block w-full rounded-sm border-gray-300 text-sm"
/>
</div>

{errorMessage && <p className="mt-1 text-sm text-red-700">{errorMessage}</p>}
</div>
</form>
</WithStep>
<WithStep step={SetupStep.DisplayQrCode} current={step}>
<>
<div className="flex justify-center">
{
// eslint-disable-next-line @next/next/no-img-element
<img src={dataUri} alt="" />
}
</div>
<p className="text-center font-mono text-xs">{secret}</p>
</>
</WithStep>
<WithStep step={SetupStep.EnterTotpCode} current={step}>
<form onSubmit={handleEnable}>
<div className="mb-4">
<label htmlFor="code" className="mt-4 block text-sm font-medium text-gray-700">
{t("code")}
</label>
<div className="mt-1">
<input
type="text"
name="code"
id="code"
required
value={totpCode}
maxLength={6}
minLength={6}
inputMode="numeric"
onInput={(e) => setTotpCode(e.currentTarget.value)}
className="block w-full rounded-sm border-gray-300 text-sm"
autoComplete="one-time-code"
/>
</div>

{errorMessage && <p className="mt-1 text-sm text-red-700">{errorMessage}</p>}
</div>
</form>
</WithStep>

<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
<WithStep step={SetupStep.ConfirmPassword} current={step}>
<Button
type="submit"
className="ltr:ml-2 rtl:mr-2"
onClick={handleSetup}
disabled={password.length === 0 || isSubmitting}>
{t("continue")}
</Button>
</WithStep>
<WithStep step={SetupStep.DisplayQrCode} current={step}>
<Button
type="submit"
className="ltr:ml-2 rtl:mr-2"
onClick={() => setStep(SetupStep.EnterTotpCode)}>
{t("continue")}
</Button>
</WithStep>
<WithStep step={SetupStep.EnterTotpCode} current={step}>
<Button
type="submit"
className="ltr:ml-2 rtl:mr-2"
onClick={handleEnable}
disabled={totpCode.length !== 6 || isSubmitting}>
{t("enable")}
</Button>
</WithStep>
<Button color="secondary" onClick={onCancel}>
{t("cancel")}
</Button>
</div>
</DialogContent>
</Dialog>
);
};

export default EnableTwoFactorModal;
33 changes: 33 additions & 0 deletions apps/web/components/v2/settings/TwoFactorAuthAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const TwoFactorAuthAPI = {
async setup(password: string) {
return fetch("/api/auth/two-factor/totp/setup", {
method: "POST",
body: JSON.stringify({ password }),
headers: {
"Content-Type": "application/json",
},
});
},

async enable(code: string) {
return fetch("/api/auth/two-factor/totp/enable", {
method: "POST",
body: JSON.stringify({ code }),
headers: {
"Content-Type": "application/json",
},
});
},

async disable(password: string) {
return fetch("/api/auth/two-factor/totp/disable", {
method: "POST",
body: JSON.stringify({ password }),
headers: {
"Content-Type": "application/json",
},
});
},
};

export default TwoFactorAuthAPI;
3 changes: 2 additions & 1 deletion apps/web/lib/app-providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DynamicHelpscoutProvider from "@calcom/features/ee/support/lib/helpscout/
import DynamicIntercomProvider from "@calcom/features/ee/support/lib/intercom/providerDynamic";
import { ContractsProvider } from "@calcom/features/ee/web3/contexts/contractsContext";
import { trpc } from "@calcom/trpc/react";
import { MetaProvider } from "@calcom/ui/v2/core/Meta";

import usePublicPage from "@lib/hooks/usePublicPage";

Expand Down Expand Up @@ -80,7 +81,7 @@ const AppProviders = (props: AppPropsWithChildren) => {
storageKey={storageKey}
forcedTheme={forcedTheme}
attribute="class">
{props.children}
<MetaProvider>{props.children}</MetaProvider>
</ThemeProvider>
</TooltipProvider>
</CustomI18nextProvider>
Expand Down
1 change: 1 addition & 0 deletions apps/web/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum ErrorCode {
InternalServerError = "internal-server-error",
NewPasswordMatchesOld = "new-password-matches-old",
ThirdPartyIdentityProviderEnabled = "third-party-identity-provider-enabled",
InvalidPassword = "invalid-password",
}

export const identityProviderNameMap: { [key in IdentityProvider]: string } = {
Expand Down
Loading