Skip to content

Commit f03773c

Browse files
authored
Add publish email option to TestListForm and update related components (#268)
1 parent 48c1f03 commit f03773c

5 files changed

Lines changed: 47 additions & 5 deletions

File tree

‎components/form/TestListForm.tsx‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { yupResolver } from '@hookform/resolvers/yup'
22
import Compact from '@uiw/react-color-compact'
33
import { format } from 'date-fns'
4-
import { Input } from 'ooni-components'
4+
import { Checkbox, Input } from 'ooni-components'
55
import { Controller, FormProvider, useForm } from 'react-hook-form'
66
import { FormattedMessage, useIntl } from 'react-intl'
77
import * as Yup from 'yup'
@@ -51,6 +51,7 @@ export type TestList = {
5151
icon: string
5252
color: string
5353
author: string
54+
publish_email: boolean
5455
expiration_date: string
5556
nettests: Nettest[]
5657
}
@@ -88,6 +89,7 @@ const validationSchema = Yup.object({
8889
icon: Yup.string().defined(),
8990
color: Yup.string().defined(),
9091
author: Yup.string().defined(),
92+
publish_email: Yup.boolean().defined(),
9193
expiration_date: Yup.string()
9294
.required('TestListForm.Validation.Required')
9395
.test(
@@ -274,7 +276,7 @@ const TestListForm = ({
274276
{...field}
275277
label={`${intl.formatMessage({ id: 'TestListForm.Label.Description' })} *`}
276278
placeholder=""
277-
minHeight="78px"
279+
style={{ minHeight: '78px' }}
278280
error={
279281
!!fieldState?.error?.message &&
280282
intl.formatMessage({ id: fieldState?.error?.message })
@@ -287,20 +289,52 @@ const TestListForm = ({
287289
<IntlFields name="description_intl" inputType="textarea" />
288290
</StyledInputWrapper>
289291
{isClient && (
290-
<StyledInputWrapper>
292+
<>
291293
<Controller
292294
render={({ field }) => (
293295
<Input
294296
{...field}
295297
disabled
296298
bg="gray3"
297299
label={`${intl.formatMessage({ id: 'TestListForm.Label.Email' })} *`}
300+
className="mb-2"
298301
/>
299302
)}
300303
name="author"
301304
control={control}
302305
/>
303-
</StyledInputWrapper>
306+
<StyledInputWrapper>
307+
<Controller
308+
render={({
309+
field: { value, onChange, ...fieldProps },
310+
}) => (
311+
<>
312+
<Checkbox
313+
{...fieldProps}
314+
onChange={(
315+
event: React.ChangeEvent<HTMLInputElement>,
316+
) => onChange(event.target.checked)}
317+
checked={value}
318+
aria-describedby="publish_email-help"
319+
label={intl.formatMessage({
320+
id: 'TestListForm.Label.PublishEmail',
321+
})}
322+
/>
323+
<p
324+
id="publish_email-help"
325+
className="text-sm text-gray-600 mt-1 ms-7"
326+
>
327+
{intl.formatMessage({
328+
id: 'TestListForm.Help.PublishEmail',
329+
})}
330+
</p>
331+
</>
332+
)}
333+
name="publish_email"
334+
control={control}
335+
/>
336+
</StyledInputWrapper>
337+
</>
304338
)}
305339

306340
<StyledInputWrapper>

‎components/v2/DescriptorDetails.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useMemo } from 'react'
55
import { useIntl } from 'react-intl'
66
import { formatMediumDate } from 'utils'
77
import ArchivedTag from '../ArchivedTag'
8+
import useUser from 'hooks/useUser'
89

910
type ExpirationDateProps = {
1011
expirationString: string
@@ -40,6 +41,9 @@ const DescriptorDetails = ({
4041
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
4142
}: any) => {
4243
const { locale, formatMessage } = useIntl()
44+
const { user } = useUser()
45+
const isAdmin = useMemo(() => user?.role === 'admin', [user])
46+
4347
return (
4448
<>
4549
<h2 className="leading-none inline align-middle mr-4">
@@ -54,7 +58,7 @@ const DescriptorDetails = ({
5458
{descriptor.is_expired && <ArchivedTag />}
5559

5660
<div className="text-sm my-4">
57-
{descriptor.author ? (
61+
{descriptor.author && (descriptor?.publish_email || isAdmin) ? (
5862
<>
5963
{formatMessage(
6064
{ id: 'DescriptorDetails.CreatedByOn' },

‎pages/create.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const defaultValues = {
4848
icon: '',
4949
color: '#000000',
5050
author: getUserEmail(),
51+
publish_email: true,
5152
expiration_date: '',
5253
nettests: [
5354
{

‎pages/edit/[linkId].tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const transformIncomingData = (formData: any) => {
2626
...formData,
2727
color: formData?.color ? formData.color : '#000000',
2828
author: formData?.author || getUserEmail(),
29+
publish_email: formData?.publish_email ?? true,
2930
name_intl: transformIntoArray(formData.name_intl),
3031
description_intl: transformIntoArray(formData.description_intl),
3132
short_description_intl: transformIntoArray(formData.short_description_intl),

‎public/static/lang/en.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
"TestListForm.Label.ShortDescription": "Short description",
4747
"TestListForm.Label.Description": "Description",
4848
"TestListForm.Label.Email": "Author's Email",
49+
"TestListForm.Label.PublishEmail": "Publish author's email",
50+
"TestListForm.Help.PublishEmail": "Others can see who created this link and contact you. Uncheck to not display your email publicly.",
4951
"TestListForm.Label.ExpirationDate": "Expiration Date",
5052
"TestListForm.Label.Icon": "Icon",
5153
"TestListForm.OptionsFields.Key": "Key",

0 commit comments

Comments
 (0)