Skip to content

Commit 2f6577e

Browse files
🔨 Refactored 🧠 Overmind Hacktober /app/pages/common/Modals/Fe… (codesandbox#2667)
* Add @ShahAnuj2610 as a contributor * refactor: packages/app/src/app/pages/common/Modals/FeedbackModal/Feedback.js to use useOvermind hook * fix: import * refactor: component and it's dependency to ts * Revert .all-contributorsrc * Revert README.md Co-authored-by: Sara Vieira <[email protected]>
1 parent 6f60ac6 commit 2f6577e

File tree

3 files changed

+137
-154
lines changed

3 files changed

+137
-154
lines changed

‎packages/app/src/app/pages/common/Modals/FeedbackModal/Feedback.js‎

Lines changed: 0 additions & 153 deletions
This file was deleted.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import * as React from 'react';
2+
import { useOvermind } from 'app/overmind';
3+
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
4+
import { Button } from '@codesandbox/common/lib/components/Button';
5+
import { CurrentUser } from '@codesandbox/common/lib/types';
6+
7+
import AutosizeTextArea from '@codesandbox/common/lib/components/AutosizeTextArea';
8+
import Input from '@codesandbox/common/lib/components/Input';
9+
import pushToAirtable from 'app/store/utils/pushToAirtable';
10+
11+
import { EmojiButton } from './elements';
12+
13+
interface ICollectionInfoProps {
14+
id: string;
15+
user: CurrentUser;
16+
}
17+
18+
const Feedback: React.FC<ICollectionInfoProps> = ({ id, user }) => {
19+
const {
20+
actions: { modalClosed, notificationAdded },
21+
} = useOvermind();
22+
23+
const [feedback, setFeedback] = React.useState('');
24+
const [email, setEmail] = React.useState((user || {}).email);
25+
const [emoji, setEmoji] = React.useState(null);
26+
const [loading, setLoading] = React.useState(false);
27+
28+
const setHappy = () => setEmoji('happy');
29+
30+
const setSad = () => setEmoji('sad');
31+
32+
const onSubmit = async evt => {
33+
evt.preventDefault();
34+
setLoading(true);
35+
try {
36+
await pushToAirtable({
37+
sandboxId: id,
38+
feedback,
39+
emoji,
40+
username: (user || {}).username,
41+
email,
42+
});
43+
setFeedback('');
44+
setEmoji(null);
45+
setLoading(false);
46+
47+
modalClosed();
48+
notificationAdded({
49+
title: `Thanks for your feedback!`,
50+
notificationType: 'success',
51+
});
52+
} catch (e) {
53+
notificationAdded({
54+
title: `Something went wrong while sending feedback: ${e.message}`,
55+
notificationType: 'error',
56+
});
57+
setLoading(false);
58+
}
59+
};
60+
61+
return (
62+
<form onSubmit={onSubmit}>
63+
<AutosizeTextArea
64+
css={`
65+
width: 100%;
66+
`}
67+
name="feedback"
68+
value={feedback}
69+
onChange={e => setFeedback(e.target.value)}
70+
placeholder="What are your thoughts?"
71+
minRows={3}
72+
required
73+
/>
74+
{!user && (
75+
<Margin top={0.5}>
76+
<Input
77+
css={`
78+
width: 100%;
79+
`}
80+
type="email"
81+
name="email"
82+
value={email}
83+
onChange={e => setEmail(e.target.value)}
84+
placeholder="Email if you wish to be contacted"
85+
/>
86+
</Margin>
87+
)}
88+
89+
<Margin
90+
top={0.5}
91+
css={`
92+
display: flex;
93+
align-items: center;
94+
`}
95+
>
96+
<EmojiButton
97+
type="button"
98+
active={emoji === 'happy'}
99+
onClick={setHappy}
100+
>
101+
<span role="img" aria-label="happy">
102+
😊
103+
</span>
104+
</EmojiButton>
105+
106+
<EmojiButton type="button" active={emoji === 'sad'} onClick={setSad}>
107+
<span role="img" aria-label="sad">
108+
😞
109+
</span>
110+
</EmojiButton>
111+
112+
<div
113+
css={`
114+
flex: 1;
115+
`}
116+
>
117+
<Button
118+
disabled={loading}
119+
small
120+
css={`
121+
float: right;
122+
`}
123+
>
124+
{loading ? 'Sending...' : 'Submit'}
125+
</Button>
126+
</div>
127+
</Margin>
128+
</form>
129+
);
130+
};
131+
132+
export default Feedback;

packages/app/src/app/pages/common/Modals/FeedbackModal/elements.js renamed to packages/app/src/app/pages/common/Modals/FeedbackModal/elements.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import styled, { css } from 'styled-components';
22

3-
export const EmojiButton = styled.button`
3+
interface Props {
4+
active: boolean;
5+
}
6+
7+
export const EmojiButton = styled.button<Props>`
48
transition: 0.3s ease all;
59
border: 2px solid rgba(0, 0, 0, 0.2);
610
background-color: rgba(0, 0, 0, 0.3);

0 commit comments

Comments
 (0)