From 20ada304036eddd9d28bf5a8a68838dc37ff496d Mon Sep 17 00:00:00 2001 From: majakomel Date: Tue, 19 Sep 2023 16:10:23 +0200 Subject: [PATCH] Temp feedback box fix --- components/Radio.js | 31 +++++++++++++++++++++++++++ components/measurement/FeedbackBox.js | 3 ++- package.json | 2 +- yarn.lock | 8 +++---- 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 components/Radio.js diff --git a/components/Radio.js b/components/Radio.js new file mode 100644 index 000000000..5cc910f24 --- /dev/null +++ b/components/Radio.js @@ -0,0 +1,31 @@ +import { Children, cloneElement, isValidElement } from 'react' +import { Flex } from 'ooni-components' + +export const RadioGroup = ({ + children, + name, + value, + onChange, + direction = 'column', + ...props +}) => { + const iterateOverChildren = (children) => { + return Children.map(children, (child) => { + if (!isValidElement(child)) return null + + return cloneElement(child, { + ...child.props, + checked: child.props.value === value, + onChange: (e) => + onChange && onChange(e.target.value), + children: iterateOverChildren(child.props.children), + }) + }) + } + + return ( + + {iterateOverChildren(children)} + + ) +} diff --git a/components/measurement/FeedbackBox.js b/components/measurement/FeedbackBox.js index 793e03999..fe4fa8a19 100644 --- a/components/measurement/FeedbackBox.js +++ b/components/measurement/FeedbackBox.js @@ -1,13 +1,14 @@ import React, { useEffect, useMemo, useRef, useState } from 'react' import { Controller, useForm } from 'react-hook-form' import { FormattedMessage, useIntl } from 'react-intl' -import { Box, Button, Flex, Link, Text, theme, RadioGroup, RadioButton } from 'ooni-components' +import { Box, Button, Flex, Text, theme, RadioButton } from 'ooni-components' import { GrClose } from 'react-icons/gr' import useStateMachine from '@cassiozen/usestatemachine' import SpinLoader from 'components/vendor/SpinLoader' import { submitFeedback, getAPI } from 'lib/api' import LoginForm from 'components/login/LoginForm' import styled from 'styled-components' +import { RadioGroup } from 'components/Radio' const StyledCloseIcon = styled(GrClose)` position: absolute; diff --git a/package.json b/package.json index bf444d2ff..687a6bc10 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "markdown-to-jsx": "^7.1.9", "next": "^12.3.1", "nprogress": "^0.2.0", - "ooni-components": "1.0.0-alpha.13", + "ooni-components": "1.0.0-alpha.14", "pretty-ms": "^8.0.0", "prop-types": "15.8.1", "react": "17.0.2", diff --git a/yarn.lock b/yarn.lock index 25d26ead1..aa5dbdfbc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5809,10 +5809,10 @@ onetime@^5.1.0, onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" -ooni-components@1.0.0-alpha.13: - version "1.0.0-alpha.13" - resolved "https://registry.yarnpkg.com/ooni-components/-/ooni-components-1.0.0-alpha.13.tgz#2699412989707432d534cf1ae45788f624474686" - integrity sha512-g2jzDfj8YdZn7OFY10E9kac9ycid8DZEWQ3tPHWDHhreRbsO2/6zUa4kEz9HBHFuix5xggR7jHepvZo+fVYJEQ== +ooni-components@1.0.0-alpha.14: + version "1.0.0-alpha.14" + resolved "https://registry.yarnpkg.com/ooni-components/-/ooni-components-1.0.0-alpha.14.tgz#d6d26944b56bf6e0be81102d7cd27a44dbc57a25" + integrity sha512-n90KEtXTKT11mA4+F3rnbwZcuZgrUJdrV38CRXgJhD6QTEU9/ADkNDO0ae0sFiR0XZkhbaBBU4hjao/TZgZIFw== dependencies: "@styled-system/css" "^5.1.5" "@styled-system/should-forward-prop" "^5.1.5"