Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

(refactoring) UI lib components (#423)

Andrii Romasiund4185fad2235
diff --git a/app/modals/Forecast.tsx b/app/modals/Forecast.tsx
index fb4dea903..6aacb84c3 100644
--- a/app/modals/Forecast.tsx
+++ b/app/modals/Forecast.tsx
@@ -72,8 +72,6 @@ const Forecast = ({ onClose, onSubmit, isOpened, activeTB, tb }: IForecast): JSX
<Input
name='forecast-input'
- id='forecast-input'
- type='text'
label={t('modals.forecast.input', {
frequency: activeTB,
})}
diff --git a/app/modals/NewFunnel.tsx b/app/modals/NewFunnel.tsx
index 39fbd2de7..9fd89d99e 100644
--- a/app/modals/NewFunnel.tsx
+++ b/app/modals/NewFunnel.tsx
@@ -113,7 +113,6 @@ const NewFunnel = ({
<div>
<Input
name='funnel-name-input'
- type='text'
label={t('modals.funnels.name')}
value={name}
onChange={(e) => setName(e.target.value)}
diff --git a/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx b/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx
index 6a0720fa4..3470352a3 100644
--- a/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx
+++ b/app/pages/Auth/CreateNewPassword/CreateNewPassword.tsx
@@ -116,7 +116,6 @@ const CreateNewPassword = ({
<form className='space-y-6' onSubmit={handleSubmit}>
<Input
name='password'
- id='password'
type='password'
label={t('auth.recovery.newPassword')}
hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}
@@ -126,7 +125,6 @@ const CreateNewPassword = ({
/>
<Input
name='repeat'
- id='repeat'
type='password'
label={t('auth.common.repeat')}
value={form.repeat}
diff --git a/app/pages/Auth/ForgotPassword/ForgotPassword.tsx b/app/pages/Auth/ForgotPassword/ForgotPassword.tsx
index b44f8beca..18677c27e 100644
--- a/app/pages/Auth/ForgotPassword/ForgotPassword.tsx
+++ b/app/pages/Auth/ForgotPassword/ForgotPassword.tsx
@@ -101,7 +101,6 @@ const ForgotPassword = ({
<form className='space-y-6' onSubmit={handleSubmit}>
<Input
name='email'
- id='email'
type='email'
label={t('auth.common.email')}
value={form.email}
diff --git a/app/pages/Auth/Signin/Signin.tsx b/app/pages/Auth/Signin/Signin.tsx
index 0ae0ab22c..f957763e7 100644
--- a/app/pages/Auth/Signin/Signin.tsx
+++ b/app/pages/Auth/Signin/Signin.tsx
@@ -133,11 +133,9 @@ const Signin = ({ login, loginSuccess, loginFailed, authSSO, ssrTheme }: ISignin
}
const handleInput = ({ target }: { target: HTMLInputElement }) => {
- const value = target.type === 'checkbox' ? target.checked : target.value
-
setForm((oldForm) => ({
...oldForm,
- [target.name]: value,
+ [target.name]: target.value,
}))
}
@@ -160,7 +158,6 @@ const Signin = ({ login, loginSuccess, loginFailed, authSSO, ssrTheme }: ISignin
{t('auth.signin.2faDesc')}
</p>
<Input
- type='text'
label={t('profileSettings.enter2faToDisable')}
value={twoFACode}
placeholder={t('auth.signin.6digitCode')}
@@ -206,7 +203,6 @@ const Signin = ({ login, loginSuccess, loginFailed, authSSO, ssrTheme }: ISignin
<form className='space-y-6' onSubmit={handleSubmit}>
<Input
name='email'
- id='email'
type='email'
label={t('auth.common.email')}
value={form.email}
@@ -216,7 +212,6 @@ const Signin = ({ login, loginSuccess, loginFailed, authSSO, ssrTheme }: ISignin
/>
<Input
name='password'
- id='password'
type='password'
label={t('auth.common.password')}
hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}
@@ -228,9 +223,13 @@ const Signin = ({ login, loginSuccess, loginFailed, authSSO, ssrTheme }: ISignin
<div className='flex items-center justify-between'>
<Checkbox
checked={form.dontRemember}
- onChange={handleInput}
+ onChange={(checked) =>
+ setForm((prev) => ({
+ ...prev,
+ dontRemember: checked,
+ }))
+ }
name='dontRemember'
- id='dontRemember'
label={t('auth.common.noRemember')}
/>
{!isSelfhosted && (
diff --git a/app/pages/Auth/Signup/BasicSignup.tsx b/app/pages/Auth/Signup/BasicSignup.tsx
index 607e17220..18221a910 100644
--- a/app/pages/Auth/Signup/BasicSignup.tsx
+++ b/app/pages/Auth/Signup/BasicSignup.tsx
@@ -111,11 +111,10 @@ const BasicSignup: React.FC<IBasicSignup> = ({ ssrTheme }): JSX.Element => {
const handleInput = (event: React.ChangeEvent<HTMLInputElement>) => {
const { target } = event
- const value = target.type === 'checkbox' ? target.checked : target.value
setForm((oldForm) => ({
...oldForm,
- [target.name]: value,
+ [target.name]: target.value,
}))
}
@@ -133,7 +132,6 @@ const BasicSignup: React.FC<IBasicSignup> = ({ ssrTheme }): JSX.Element => {
<form className='space-y-6' onSubmit={handleSubmit}>
<Input
name='email'
- id='email'
type='email'
value={form.email}
placeholder={t('auth.signup.email')}
@@ -142,7 +140,6 @@ const BasicSignup: React.FC<IBasicSignup> = ({ ssrTheme }): JSX.Element => {
/>
<Input
name='password'
- id='password'
type='password'
value={form.password}
placeholder={t('auth.common.password')}
@@ -152,7 +149,6 @@ const BasicSignup: React.FC<IBasicSignup> = ({ ssrTheme }): JSX.Element => {
/>
<Input
name='repeat'
- id='repeat'
type='password'
value={form.repeat}
placeholder={t('auth.common.repeat')}
@@ -163,9 +159,13 @@ const BasicSignup: React.FC<IBasicSignup> = ({ ssrTheme }): JSX.Element => {
<div className='mt-4 flex'>
<Checkbox
checked={form.checkIfLeaked}
- onChange={handleInput}
+ onChange={(checked) =>
+ setForm((prev) => ({
+ ...prev,
+ checkIfLeaked: checked,
+ }))
+ }
name='checkIfLeaked'
- id='checkIfLeaked'
label={t('auth.common.checkLeakedPassword')}
/>
<Tooltip
diff --git a/app/pages/Auth/Signup/Signup.tsx b/app/pages/Auth/Signup/Signup.tsx
index a249e5bf4..4cde7be00 100644
--- a/app/pages/Auth/Signup/Signup.tsx
+++ b/app/pages/Auth/Signup/Signup.tsx
@@ -134,11 +134,10 @@ const Signup = ({ signup, authSSO, ssrTheme, authenticated: reduxAuthenticated,
const handleInput = (event: React.ChangeEvent<HTMLInputElement>) => {
const { target } = event
- const value = target.type === 'checkbox' ? target.checked : target.value
setForm((oldForm) => ({
...oldForm,
- [target.name]: value,
+ [target.name]: target.value,
}))
}
@@ -169,7 +168,6 @@ const Signup = ({ signup, authSSO, ssrTheme, authenticated: reduxAuthenticated,
<form className='space-y-6' onSubmit={handleSubmit}>
<Input
name='email'
- id='email'
type='email'
label={t('auth.common.email')}
value={form.email}
@@ -178,7 +176,6 @@ const Signup = ({ signup, authSSO, ssrTheme, authenticated: reduxAuthenticated,
/>
<Input
name='password'
- id='password'
type='password'
label={t('auth.common.password')}
hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}
@@ -188,7 +185,6 @@ const Signup = ({ signup, authSSO, ssrTheme, authenticated: reduxAuthenticated,
/>
<Input
name='repeat'
- id='repeat'
type='password'
label={t('auth.common.repeat')}
value={form.repeat}
@@ -197,9 +193,13 @@ const Signup = ({ signup, authSSO, ssrTheme, authenticated: reduxAuthenticated,
/>
<Checkbox
checked={form.tos}
- onChange={handleInput}
+ onChange={(checked) =>
+ setForm((prev) => ({
+ ...prev,
+ tos: checked,
+ }))
+ }
name='tos'
- id='tos'
label={
<span>
<Trans
@@ -233,9 +233,13 @@ const Signup = ({ signup, authSSO, ssrTheme, authenticated: reduxAuthenticated,
<div className='flex'>
<Checkbox
checked={form.checkIfLeaked}
- onChange={handleInput}
+ onChange={(checked) =>
+ setForm((prev) => ({
+ ...prev,
+ checkIfLeaked: checked,
+ }))
+ }
name='checkIfLeaked'
- id='checkIfLeaked'
label={t('auth.common.checkLeakedPassword')}
/>
<Tooltip
diff --git a/app/pages/Captcha/Settings/CaptchaSettings.tsx b/app/pages/Captcha/Settings/CaptchaSettings.tsx
index 54b5d943b..4fbff7d6e 100644
--- a/app/pages/Captcha/Settings/CaptchaSettings.tsx
+++ b/app/pages/Captcha/Settings/CaptchaSettings.tsx
@@ -284,11 +284,10 @@ const CaptchaSettings = ({
const handleInput = (event: React.ChangeEvent<HTMLInputElement>) => {
const { target } = event
- const value = target.type === 'checkbox' ? target.checked : target.value
setForm((oldForm) => ({
...oldForm,
- [target.name]: value,
+ [target.name]: target.value,
}))
}
@@ -407,8 +406,6 @@ const CaptchaSettings = ({
{tab === tabForNew && (
<Input
name='name'
- id='name'
- type='text'
label={t('project.captcha.settings.name')}
value={form.name}
placeholder='My awesome project'
@@ -433,8 +430,6 @@ const CaptchaSettings = ({
<>
<Input
name='id'
- id='id'
- type='text'
label={t('project.captcha.settings.pid')}
value={form.id}
className='mt-4'
@@ -444,8 +439,6 @@ const CaptchaSettings = ({
/>
<Input
name='origins'
- id='origins'
- type='text'
label={t('project.settings.origins')}
hint={t('project.settings.originsHint')}
value={(form.origins as string) || ''}
@@ -455,8 +448,6 @@ const CaptchaSettings = ({
/>
<Input
name='ipBlacklist'
- id='ipBlacklist'
- type='text'
label={t('project.settings.ipBlacklist')}
hint={t('project.settings.ipBlacklistHint')}
value={(form.ipBlacklist as string) || ''}
@@ -481,8 +472,6 @@ const CaptchaSettings = ({
<div className='group relative'>
<Input
name='sercretKey'
- id='sercretKey'
- type='text'
className='pr-9'
value={captchaSecretKey}
onChange={handleInput}
@@ -525,18 +514,26 @@ const CaptchaSettings = ({
<hr className='mt-5 border-gray-200 dark:border-gray-600' />
<Checkbox
checked={Boolean(form.active)}
- onChange={handleInput}
+ onChange={(checked) =>
+ setForm((prev) => ({
+ ...prev,
+ active: checked,
+ }))
+ }
name='active'
- id='active'
className='mt-4'
label={t('project.captcha.settings.enabled')}
hint={t('project.captcha.settings.enabledHint')}
/>
<Checkbox
checked={Boolean(form.public)}
- onChange={handleInput}
+ onChange={(checked) =>
+ setForm((prev) => ({
+ ...prev,
+ public: checked,
+ }))
+ }
name='public'
- id='public'
className='mt-4'
label={t('project.settings.public')}
hint={t('project.settings.publicHint')}
diff --git a/app/pages/Captcha/View/ViewCaptcha.tsx b/app/pages/Captcha/View/ViewCaptcha.tsx
index df5560d65..06946c37e 100644
--- a/app/pages/Captcha/View/ViewCaptcha.tsx
+++ b/app/pages/Captcha/View/ViewCaptcha.tsx
@@ -743,13 +743,12 @@ const ViewCaptcha = ({
title={t('project.metricVis')}
className={cx({ hidden: isPanelsDataEmpty || analyticsLoading })}
labelExtractor={(pair) => {
- const { label, id: pairID, active } = pair
+ const { label, active } = pair
return (
<Checkbox
className={cx('px-4 py-2', { hidden: isPanelsDataEmpty || analyticsLoading })}
label={label}
- id={pairID}
checked={active}
onChange={() => {}}
/>
diff --git a/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx b/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx
index a364e6407..fb3fce439 100644
--- a/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx
+++ b/app/pages/Project/Alerts/Settings/ProjectAlertsSettings.tsx
@@ -221,11 +221,10 @@ const ProjectAlertsSettings = ({
const handleInput = (event: React.ChangeEvent<HTMLInputElement>) => {
const { target } = event
- const value = target.type === 'checkbox' ? target.checked : target.value
setForm((prevForm) => ({
...prevForm,
- [target.name]: value,
+ [target.name]: target.value,
}))
}
@@ -269,8 +268,6 @@ const ProjectAlertsSettings = ({
)}
<Input
name='name'
- id='name'
- type='text'
label={t('alert.name')}
value={form.name || ''}
placeholder={t('alert.name')}
@@ -280,9 +277,13 @@ const ProjectAlertsSettings = ({
/>
<Checkbox
checked={Boolean(form.active)}
- onChange={handleInput}
+ onChange={(checked) =>
+ setForm((prev) => ({
+ ...prev,
+ active: checked,
+ }))
+ }
name='active'
- id='active'
className='mt-4'
label={t('alert.enabled')}
hint={t('alert.enabledHint')}
@@ -307,8 +308,6 @@ const ProjectAlertsSettings = ({
{form.queryMetric === QUERY_METRIC.CUSTOM_EVENTS && (
<Input
name='queryCustomEvent'
- id='queryCustomEvent'
- type='text'
label={t('alert.customEvent')}
value={form.queryCustomEvent || ''}
placeholder={t('alert.customEvent')}
@@ -336,8 +335,6 @@ const ProjectAlertsSettings = ({
</div>
<Input
name='queryValue'
- id='queryValue'
- type='text'
label={t('alert.threshold')}
value={form.queryValue || ''}
placeholder='10'
diff --git a/app/pages/Project/New/index.tsx b/app/pages/Project/New/index.tsx
index d68c12005..eeccd973a 100644
--- a/app/pages/Project/New/index.tsx
+++ b/app/pages/Project/New/index.tsx
@@ -151,8 +151,6 @@ const NewProject = () => {
<h2 className='mt-2 text-3xl font-bold text-gray-900 dark:text-gray-50'>{t('project.settings.create')}</h2>
<Input
name='name'
- id='name'
- type='text'
label={t('project.settings.name')}
value={form.name}
placeholder='My awesome project'
diff --git a/app/pages/Project/ProjectProtectedPassword/index.tsx b/app/pages/Project/ProjectProtectedPassword/index.tsx
index eb582dd56..51106b625 100644
--- a/app/pages/Project/ProjectProtectedPassword/index.tsx
+++ b/app/pages/Project/ProjectProtectedPassword/index.tsx
@@ -128,7 +128,6 @@ const ProjectProtectedPassword = ({
<h2 className='mt-2 text-3xl font-bold text-gray-900 dark:text-gray-50'>{t('titles.passwordProtected')}</h2>
<Input
name='password'
- id='password'
type='password'
label={t('auth.common.password')}
value={form.password}
diff --git a/app/pages/Project/Settings/Emails/Emails.tsx b/app/pages/Project/Settings/Emails/Emails.tsx
index edcaf38c3..13892dfe7 100644
--- a/app/pages/Project/Settings/Emails/Emails.tsx
+++ b/app/pages/Project/Settings/Emails/Emails.tsx
@@ -52,7 +52,6 @@ const ModalMessage = ({
<p className='mt-2 text-base text-gray-700 dark:text-gray-200'>{t('project.settings.inviteDesc')}</p>
<Input
name='email'
- id='email'
type='email'
label={t('auth.common.email')}
value={form.email}
diff --git a/app/pages/Project/Settings/People/People.tsx b/app/pages/Project/Settings/People/People.tsx
index 77bbe00ec..63c4a8858 100644
--- a/app/pages/Project/Settings/People/People.tsx
+++ b/app/pages/Project/Settings/People/People.tsx
@@ -407,7 +407,6 @@ const People: React.FunctionComponent<IPeopleProps> = ({
</p>
<Input
name='email'
- id='email'
type='email'
label={t('auth.common.email')}
value={form.email}
diff --git a/app/pages/Project/Settings/ProjectSettings.tsx b/app/pages/Project/Settings/ProjectSettings.tsx
index 42b1a6ea4..ea6495e30 100644
--- a/app/pages/Project/Settings/ProjectSettings.tsx
+++ b/app/pages/Project/Settings/ProjectSettings.tsx
@@ -570,8 +570,6 @@ const ProjectSettings = ({
<h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>{t('profileSettings.general')}</h3>
<Input
name='name'
- id='name'
- type='text'
label={t('project.settings.name')}
value={form.name}
placeholder='My awesome project'
@@ -581,8 +579,6 @@ const ProjectSettings = ({
/>
<Input
name='id'
- id='id'
- type='text'
label={t('project.settings.pid')}
value={form.id}
className='mt-4'
@@ -592,8 +588,6 @@ const ProjectSettings = ({
/>
<Input
name='sharableLink'
- id='sharableLink'
- type='text'
label={t('project.settings.sharableLink')}
hint={t('project.settings.sharableDesc')}
value={`https://swetrix.com/projects/${form.id}`}
@@ -604,8 +598,6 @@ const ProjectSettings = ({
/>
<Input
name='origins'
- id='origins'
- type='text'
label={t('project.settings.origins')}
hint={t('project.settings.originsHint')}
value={form.origins || ''}
@@ -615,8 +607,6 @@ const ProjectSettings = ({
/>
<Input
name='ipBlacklist'
- id='ipBlacklist'
- type='text'
label={t('project.settings.ipBlacklist')}
hint={t('project.settings.ipBlacklistHint')}
value={form.ipBlacklist || ''}
@@ -626,22 +616,28 @@ const ProjectSettings = ({
/>
<Checkbox
checked={Boolean(form.active)}
- onChange={handleInput}
+ onChange={(checked) =>
+ setForm((prev) => ({
+ ...prev,
+ active: checked,
+ }))
+ }
name='active'
- id='active'
className='mt-4'
label={t('project.settings.enabled')}
hint={t('project.settings.enabledHint')}
/>
<Checkbox
checked={Boolean(form.public)}
- onChange={(e: any) => {
+ onChange={(checked) => {
if (!form.isPasswordProtected) {
- handleInput(e)
+ setForm((prev) => ({
+ ...prev,
+ public: checked,
+ }))
}
}}
name='public'
- id='public'
className='mt-4'
label={t('project.settings.public')}
hint={t('project.settings.publicHint')}
@@ -662,7 +658,6 @@ const ProjectSettings = ({
}
}}
name='isPasswordProtected'
- id='isPasswordProtected'
className='mt-4'
label={t('project.settings.protected')}
hint={t('project.settings.protectedHint')}
@@ -783,7 +778,6 @@ const ProjectSettings = ({
<p className='mb-4 mt-1 text-sm text-gray-500 dark:text-gray-300'>{t('project.settings.protectedHint')}</p>
<Input
name='password'
- id='password'
type='password'
label={t('project.settings.password')}
value={form?.password || ''}
@@ -811,7 +805,6 @@ const ProjectSettings = ({
</p>
<Input
name='email'
- id='email'
type='email'
label={t('project.settings.transfereeEmail')}
value={transferEmail}
diff --git a/app/pages/Project/View/ViewProject.tsx b/app/pages/Project/View/ViewProject.tsx
index 311223ba3..55c61dc4a 100644
--- a/app/pages/Project/View/ViewProject.tsx
+++ b/app/pages/Project/View/ViewProject.tsx
@@ -3720,7 +3720,6 @@ const ViewProject = ({
event.label
)
}
- id={event.id}
onChange={() => {}}
checked={event.active}
/>
@@ -3752,7 +3751,6 @@ const ViewProject = ({
className={cx('px-4 py-2', { hidden: isPanelsDataEmpty || analyticsLoading })}
label={label}
disabled={conflicted}
- id={pairID}
checked={active}
/>
)
@@ -3814,9 +3812,9 @@ const ViewProject = ({
items={errorFilters}
title={t('project.filters')}
labelExtractor={(pair) => {
- const { label, id: pairID, active } = pair
+ const { label, active } = pair
- return <Checkbox className='px-4 py-2' label={label} id={pairID} checked={active} />
+ return <Checkbox className='px-4 py-2' label={label} checked={active} />
}}
selectItemClassName='group text-gray-700 dark:text-gray-50 dark:border-gray-800 dark:bg-slate-800 block text-sm cursor-pointer hover:bg-gray-200 dark:hover:bg-slate-700'
keyExtractor={(pair) => pair.id}
diff --git a/app/pages/Project/View/components/SearchFilters.tsx b/app/pages/Project/View/components/SearchFilters.tsx
index 49abd2fc5..343211d3d 100644
--- a/app/pages/Project/View/components/SearchFilters.tsx
+++ b/app/pages/Project/View/components/SearchFilters.tsx
@@ -211,9 +211,8 @@ const SearchFilters = ({
})}
<Checkbox
checked={Boolean(override)}
- onChange={(e) => setOverride(e.target.checked)}
+ onChange={setOverride}
name='overrideCurrentlyFilters'
- id='overrideCurrentlyFilters'
className='mt-4'
label={t('project.overrideCurrentlyFilters')}
/>
diff --git a/app/pages/UserSettings/UserSettings.tsx b/app/pages/UserSettings/UserSettings.tsx
index 2809483f8..817585f59 100644
--- a/app/pages/UserSettings/UserSettings.tsx
+++ b/app/pages/UserSettings/UserSettings.tsx
@@ -336,13 +336,11 @@ const UserSettings = ({
}
}
- const handleShowLiveVisitorsSave = (e: React.ChangeEvent<HTMLInputElement>) => {
+ const handleShowLiveVisitorsSave = (checked: boolean) => {
if (settingUpdating) {
return
}
- const { checked } = e.target
-
setSettingUpdating(true)
updateShowLiveVisitorsInTitle(checked, (isSuccess: boolean) => {
setSettingUpdating(false)
@@ -356,13 +354,11 @@ const UserSettings = ({
})
}
- const handleReceiveLoginNotifications = async (e: React.ChangeEvent<HTMLInputElement>) => {
+ const handleReceiveLoginNotifications = async (checked: boolean) => {
if (settingUpdating) {
return
}
- const { checked } = e.target
-
setSettingUpdating(true)
try {
@@ -602,7 +598,6 @@ const UserSettings = ({
</h3>
<Input
name='email'
- id='email'
type='email'
label={t('auth.common.email')}
value={form.email}
@@ -629,7 +624,6 @@ const UserSettings = ({
<div className='mt-4 grid grid-cols-1 gap-x-4 gap-y-6 sm:grid-cols-6'>
<Input
name='password'
- id='password'
type='password'
label={t('auth.common.password')}
hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}
@@ -641,7 +635,6 @@ const UserSettings = ({
/>
<Input
name='repeat'
- id='repeat'
type='password'
label={t('auth.common.repeat')}
value={form.repeat}
@@ -677,8 +670,6 @@ const UserSettings = ({
<div className='group relative'>
<Input
name='apiKey'
- id='apiKey'
- type='text'
className='pr-9'
value={user.apiKey}
onChange={handleInput}
@@ -897,7 +888,6 @@ const UserSettings = ({
onChange={handleShowLiveVisitorsSave}
disabled={settingUpdating}
name='active'
- id='active'
className='mt-4'
label={t('profileSettings.showVisitorsInTitle')}
/>
@@ -955,7 +945,6 @@ const UserSettings = ({
onChange={handleReceiveLoginNotifications}
disabled={settingUpdating}
name='receiveLoginNotifications'
- id='receiveLoginNotifications'
className='mt-4'
label={t('profileSettings.receiveLoginNotifications')}
/>
@@ -1025,7 +1014,6 @@ const UserSettings = ({
<>
{t('profileSettings.deactivateConfirmation')}
<Textarea
- id='feedback'
className='mt-4'
placeholder={t('profileSettings.deletionFeedback')}
onChange={(e) => setDeletionFeedback(e.target.value)}
diff --git a/app/pages/UserSettings/components/Integrations.tsx b/app/pages/UserSettings/components/Integrations.tsx
index 81fae8062..795faff76 100644
--- a/app/pages/UserSettings/components/Integrations.tsx
+++ b/app/pages/UserSettings/components/Integrations.tsx
@@ -143,7 +143,6 @@ const Integrations = ({
</p>
<div className='mt-4 flex items-center'>
<Input
- type='text'
label={t('profileSettings.chatID')}
value={tgChatId || ''}
placeholder={t('profileSettings.chatID')}
diff --git a/app/pages/UserSettings/components/Referral.tsx b/app/pages/UserSettings/components/Referral.tsx
index 01034a9cc..98ea9d8c1 100644
--- a/app/pages/UserSettings/components/Referral.tsx
+++ b/app/pages/UserSettings/components/Referral.tsx
@@ -185,7 +185,6 @@ const Referral = ({
</p>
<div className='mt-2 flex space-x-2'>
<Input
- id='paypal-email'
type='email'
value={paypalEmailAddress || ''}
placeholder='[email protected]'
@@ -210,7 +209,7 @@ const Referral = ({
{user.refCode ? (
<div className='grid grid-cols-1 gap-x-4 gap-y-6 lg:grid-cols-2'>
<div className='group relative'>
- <Input name='refCode' id='refCode' type='text' className='pr-9' value={refUrl} disabled />
+ <Input name='refCode' className='pr-9' value={refUrl} disabled />
<div className='absolute right-2 top-3'>
<div className='group relative'>
<Button
diff --git a/app/pages/UserSettings/components/TwoFA.tsx b/app/pages/UserSettings/components/TwoFA.tsx
index 39cbcd0f5..23e00995a 100644
--- a/app/pages/UserSettings/components/TwoFA.tsx
+++ b/app/pages/UserSettings/components/TwoFA.tsx
@@ -126,7 +126,7 @@ const TwoFA = ({
return (
<div className='max-w-prose'>
<p className='text-base text-gray-900 dark:text-gray-50'>{t('profileSettings.2faRecoveryNote')}</p>
- <Input type='text' className='mt-4' value={twoFARecovery} />
+ <Input className='mt-4' value={twoFARecovery} />
<Button onClick={recoverySaved} primary large>
{t('profileSettings.2faRecoverySaved')}
</Button>
@@ -141,7 +141,6 @@ const TwoFA = ({
<p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>{t('profileSettings.2faDisableHint')}</p>
<div className='mt-4 flex items-center'>
<Input
- type='text'
label={t('profileSettings.enter2faToDisable')}
value={twoFACode}
placeholder={t('profileSettings.yourOneTimeCode')}
@@ -190,7 +189,6 @@ const TwoFA = ({
</p>
<div className='mt-4 flex items-center'>
<Input
- type='text'
label={t('profileSettings.enter2faToEnable')}
value={twoFACode}
placeholder={t('profileSettings.yourOneTimeCode')}
diff --git a/app/ui/Beta.tsx b/app/ui/Beta.tsx
index 1984f5485..c94f6f7b3 100644
--- a/app/ui/Beta.tsx
+++ b/app/ui/Beta.tsx
@@ -8,10 +8,7 @@ interface IBeta {
className?: string
}
-const Beta = ({
- // (string): Additional CSS classes to be applied to the alert container.
- className,
-}: IBeta): JSX.Element => {
+const Beta = ({ className }: IBeta): JSX.Element => {
const { t } = useTranslation('common')
return (
diff --git a/app/ui/Button.tsx b/app/ui/Button.tsx
index 0508ea81a..60fa00083 100644
--- a/app/ui/Button.tsx
+++ b/app/ui/Button.tsx
@@ -1,10 +1,11 @@
/* eslint-disable react/button-has-type */
-import React, { ButtonHTMLAttributes, memo } from 'react'
+import React, { memo } from 'react'
+import { Button as HeadlessButton } from '@headlessui/react'
import cx from 'clsx'
import Spin from './icons/Spin'
// Define the prop types for the component
-interface IButton extends React.DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
+interface IButton extends React.ButtonHTMLAttributes<HTMLButtonElement> {
// (string): The text to be displayed in the button.
text?: string
// (node): The content to be displayed in the button.
@@ -56,7 +57,7 @@ const Button = ({
disabled,
...props
}: IButton): JSX.Element => (
- <button
+ <HeadlessButton
{...props}
disabled={disabled || loading}
type={type}
@@ -64,7 +65,7 @@ const Button = ({
className={cx(
'relative inline-flex select-none items-center rounded-md border font-medium leading-4',
{
- 'border-transparent bg-slate-900 text-gray-50 shadow-sm hover:bg-slate-700 dark:bg-indigo-700 dark:hover:bg-indigo-800':
+ 'border-transparent bg-slate-900 text-gray-50 shadow-sm hover:bg-slate-700 dark:bg-white/10 dark:hover:bg-white/20':
primary,
'border-transparent bg-slate-300 text-slate-900 hover:bg-slate-200': secondary,
'border-transparent bg-white text-gray-700 hover:bg-gray-50': white,
@@ -85,7 +86,7 @@ const Button = ({
>
{loading && <Spin alwaysLight />}
{text || children}
- </button>
+ </HeadlessButton>
)
export default memo(Button)
diff --git a/app/ui/Checkbox.tsx b/app/ui/Checkbox.tsx
index 799913f91..d4215a32a 100644
--- a/app/ui/Checkbox.tsx
+++ b/app/ui/Checkbox.tsx
@@ -1,13 +1,14 @@
import React, { memo } from 'react'
+import { Checkbox as HeadlessCheckbox, Description, Field, Label } from '@headlessui/react'
+import { CheckIcon } from '@heroicons/react/24/outline'
import cx from 'clsx'
interface ICheckbox {
label: string | JSX.Element
hint?: string | JSX.Element
- id?: string
name?: string
className?: string
- onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
+ onChange?: (checked: boolean) => void
checked?: boolean
hintClassName?: string
disabled?: boolean
@@ -16,58 +17,29 @@ interface ICheckbox {
const Checkbox = ({
label,
hint,
- id,
name,
className,
onChange,
checked,
hintClassName,
disabled,
-}: ICheckbox): JSX.Element => {
- const identifier = id || name
-
- return (
- <div
- className={cx(
- 'relative flex items-start whitespace-pre-line',
- {
- 'cursor-not-allowed': disabled,
- },
- className,
- )}
- >
- <div className='flex h-5 items-center'>
- <input
- id={identifier}
- aria-describedby={identifier}
- name={name}
- disabled={disabled}
- type='checkbox'
- checked={checked}
- onChange={onChange}
- className={cx(
- 'h-4 w-4 cursor-pointer rounded border-gray-300 text-indigo-600 focus:ring-indigo-500 dark:border-slate-800 dark:bg-slate-700 dark:checked:bg-indigo-600',
- { '!cursor-not-allowed': disabled, 'opacity-50': disabled },
- )}
- />
- </div>
- <div className='ml-3 text-sm'>
- <label
- htmlFor={identifier}
- className={cx('cursor-pointer font-medium text-gray-700 dark:text-gray-200', {
- '!cursor-not-allowed': disabled,
- })}
- >
- {label}
- </label>
- {hint && (
- <p id={`${identifier}-description`} className={cx('text-gray-500 dark:text-gray-300', hintClassName)}>
- {hint}
- </p>
- )}
- </div>
+}: ICheckbox): JSX.Element => (
+ <Field className={className} disabled={disabled}>
+ <div className='flex items-center gap-2'>
+ <HeadlessCheckbox
+ name={name}
+ checked={checked}
+ onChange={onChange}
+ className='group size-4 rounded bg-white ring-1 ring-inset ring-gray-200 data-[checked]:bg-slate-900 data-[checked]:ring-slate-900 dark:bg-white/10 dark:ring-white/15 dark:data-[checked]:bg-white dark:data-[checked]:ring-white/15'
+ >
+ <CheckIcon className='hidden size-4 text-white group-data-[checked]:block dark:text-black' />
+ </HeadlessCheckbox>
+ <Label className='cursor-pointer text-sm font-medium text-gray-700 dark:text-gray-200'>{label}</Label>
</div>
- )
-}
+ {hint && (
+ <Description className={cx('mt-1 text-sm text-gray-500 dark:text-gray-300', hintClassName)}>{hint}</Description>
+ )}
+ </Field>
+)
export default memo(Checkbox)
diff --git a/app/ui/Highlighted.tsx b/app/ui/Highlighted.tsx
index 6c9adc567..e50c9d26f 100644
--- a/app/ui/Highlighted.tsx
+++ b/app/ui/Highlighted.tsx
@@ -5,7 +5,7 @@ interface IHighlighted {
}
const Highlighted = ({ children }: IHighlighted) => (
- <span className='rounded bg-slate-200 px-1 text-gray-900 dark:bg-slate-700 dark:text-gray-50'>{children}</span>
+ <span className='rounded bg-slate-200 px-1 text-gray-900 dark:bg-slate-700 dark:text-gray-50'>{children}</span>
)
export default Highlighted
diff --git a/app/ui/Input.tsx b/app/ui/Input.tsx
index f6c584093..5492669d0 100644
--- a/app/ui/Input.tsx
+++ b/app/ui/Input.tsx
@@ -1,7 +1,7 @@
import React, { memo } from 'react'
+import { Description, Field, Input as HeadlessInput, Label } from '@headlessui/react'
import cx from 'clsx'
import _isEmpty from 'lodash/isEmpty'
-import { ExclamationCircleIcon } from '@heroicons/react/24/solid'
import Beta from 'ui/Beta'
interface IInput {
@@ -9,7 +9,6 @@ interface IInput {
hint?: string | JSX.Element
placeholder?: string
type?: string
- id?: string
name?: string
className?: string
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
@@ -24,8 +23,7 @@ const Input = ({
label,
hint,
placeholder,
- type,
- id,
+ type = 'text',
name,
className,
onChange,
@@ -35,65 +33,40 @@ const Input = ({
onKeyDown,
isBeta,
}: IInput): JSX.Element => {
- const identifier = id || name || type
const isError = !_isEmpty(error)
return (
- <div className={className}>
- <div
- className={cx({
- 'flex justify-between': label && hint,
- })}
- >
- <label htmlFor={identifier} className='flex text-sm font-medium text-gray-700 dark:text-gray-200'>
- {label}
- {isBeta && (
- <div className='ml-5'>
- <Beta />
- </div>
- )}
- </label>
- </div>
- <div
- className={cx('relative', {
- 'mt-1': label,
- })}
- >
- <input
- type={type}
- value={value}
- name={name}
- id={identifier}
- onChange={onChange}
- onKeyDown={onKeyDown}
- className={cx(
- 'block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-slate-800/25 dark:bg-slate-800 dark:text-gray-50 dark:placeholder-gray-400 sm:text-sm',
- {
- 'border-red-300 text-red-900 placeholder-red-300': isError,
- 'cursor-text': disabled,
- },
- )}
- placeholder={placeholder}
- aria-describedby={`${identifier}-optional`}
- disabled={disabled}
- />
- {isError && (
- <div className='pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3'>
- <ExclamationCircleIcon className='h-5 w-5 text-red-500' aria-hidden />
+ <Field as='div' className={className}>
+ <Label className='mb-1 flex text-sm font-medium text-gray-700 dark:text-gray-200'>
+ {label}
+ {isBeta && (
+ <div className='ml-5'>
+ <Beta />
</div>
)}
- </div>
+ </Label>
+ <HeadlessInput
+ type={type}
+ value={value}
+ name={name}
+ onChange={onChange}
+ onKeyDown={onKeyDown}
+ className={cx(
+ 'block w-full rounded-md border-gray-300 shadow-sm dark:border-slate-800/25 dark:bg-slate-800 dark:text-gray-50 dark:placeholder-gray-400 sm:text-sm',
+ {
+ 'text-red-900 placeholder-red-300 ring-1 ring-red-600': isError,
+ 'cursor-text': disabled,
+ },
+ )}
+ placeholder={placeholder}
+ disabled={disabled}
+ invalid={isError}
+ />
+ {isError && <p className='mt-2 text-sm text-red-600 dark:text-red-500'>{error}</p>}
{hint && (
- <p className='mt-2 whitespace-pre-line text-sm text-gray-500 dark:text-gray-300' id={`${identifier}-optional`}>
- {hint}
- </p>
- )}
- {isError && (
- <p className='mt-2 text-sm text-red-600 dark:text-red-500' id='email-error'>
- {error}
- </p>
+ <Description className='mt-2 whitespace-pre-line text-sm text-gray-500 dark:text-gray-300'>{hint}</Description>
)}
- </div>
+ </Field>
)
}
diff --git a/app/ui/Textarea.tsx b/app/ui/Textarea.tsx
index 095a33c3f..21db20ae3 100644
--- a/app/ui/Textarea.tsx
+++ b/app/ui/Textarea.tsx
@@ -1,8 +1,7 @@
import React, { memo } from 'react'
+import { Description, Field, Label, Textarea as HeadlessTextarea } from '@headlessui/react'
import cx from 'clsx'
import _isEmpty from 'lodash/isEmpty'
-import { ExclamationCircleIcon } from '@heroicons/react/24/solid'
-import Beta from 'ui/Beta'
interface ITextarea {
value: string | number
@@ -10,13 +9,10 @@ interface ITextarea {
hint?: string
placeholder?: string
onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void
- id?: string
- type?: string
className?: string
error?: string | boolean
name?: string
disabled?: boolean
- isBeta?: boolean
readOnly?: boolean
rows?: number
}
@@ -25,66 +21,42 @@ const Textarea = ({
label,
hint,
placeholder,
- type,
- id,
name,
className,
onChange,
error,
value,
disabled,
- isBeta,
readOnly,
rows = 4,
}: ITextarea) => {
- const identifier = `textarea-${id || name || type}`
const isError = !_isEmpty(error)
return (
- <div className={className}>
- {label && (
- <label htmlFor={identifier} className='flex text-sm font-medium text-gray-700 dark:text-gray-200'>
- {label}
- {isBeta && (
- <div className='ml-5'>
- <Beta />
- </div>
- )}
- </label>
- )}
- <div className='relative mt-1'>
- <textarea
- rows={rows}
- name={identifier}
- id={identifier}
- className={cx(
- 'block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-slate-800/25 dark:bg-slate-800 dark:text-gray-50 dark:placeholder-gray-400 sm:text-sm',
- {
- 'border-red-300 text-red-900 placeholder-red-300': isError,
- 'cursor-text': disabled,
- },
- )}
- value={value}
- onChange={onChange}
- placeholder={placeholder}
- disabled={disabled}
- readOnly={readOnly}
- />
- {isError && (
- <div className='pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3'>
- <ExclamationCircleIcon className='h-5 w-5 text-red-500' aria-hidden />
- </div>
+ <Field as='div' className={className}>
+ {label && <Label className='flex text-sm font-medium text-gray-700 dark:text-gray-200'>{label}</Label>}
+ <HeadlessTextarea
+ rows={rows}
+ name={name}
+ className={cx(
+ 'block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-slate-800/25 dark:bg-slate-800 dark:text-gray-50 dark:placeholder-gray-400 sm:text-sm',
+ {
+ 'text-red-900 placeholder-red-300 ring-1 ring-red-600': isError,
+ 'cursor-text': disabled,
+ },
)}
- </div>
- <p className='mt-2 whitespace-pre-line text-sm text-gray-500 dark:text-gray-300' id={`${identifier}-optional`}>
- {hint}
- </p>
- {isError && (
- <p className='mt-2 text-sm text-red-600 dark:text-red-500' id='email-error'>
- {error}
- </p>
+ value={value}
+ onChange={onChange}
+ placeholder={placeholder}
+ disabled={disabled}
+ readOnly={readOnly}
+ invalid={isError}
+ />
+ {isError && <p className='mt-2 text-sm text-red-600 dark:text-red-500'>{error}</p>}
+ {hint && (
+ <Description className='mt-2 whitespace-pre-line text-sm text-gray-500 dark:text-gray-300'>{hint}</Description>
)}
- </div>
+ </Field>
)
}