Skip to content

Commit 1c6b149

Browse files
author
Alessandro Mazzon
authored
fix(#345): Already reported post (#442)
## Already reported post Closes: #345 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] provided a link to the relevant issue or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed all author checklist items have been addressed
1 parent 9844533 commit 1c6b149

2 files changed

Lines changed: 89 additions & 50 deletions

File tree

src/assets/locales/en/reportPost.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"report": "Report",
99
"submit": "Submit",
1010
"message": "Add more details",
11+
"already reported": "Already reported",
12+
"already reported message": "You have already reported this post",
1113
"thanks for reporting": "Thank you for reporting",
12-
"report success message": "Thank you for taking your time to report this post. In case the post violates our community guidelines, Butter will take care of handling the post."
14+
"report success message": "In case the post violates our community guidelines, our support will take care of it"
1315
}

src/screens/Modals/ReportPost/index.tsx

Lines changed: 86 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { reportSuccessIcon } from 'assets/images';
2020
import { isPostAlreadyReportedError } from 'types/error';
2121
import CommonStyles from 'config/theme/CommonStyles';
2222
import StyledSpinner from 'components/StyledSpinner';
23+
import useCustomToast from 'hooks/extended/useCustomToast';
2324
import useStyles from './useStyles';
2425

2526
export type ReportPostParams = {
@@ -36,10 +37,10 @@ const ReportPost = () => {
3637
const { t } = useTranslation('reportPost');
3738
const styles = useStyles();
3839
const theme = useTheme();
39-
4040
const { goBack } = useNavigation<NavProps['navigation']>();
4141
const { params } = useRoute<NavProps['route']>();
4242
const { post } = params;
43+
const toast = useCustomToast();
4344

4445
// -------------------------------------------------------------------------------------
4546
// --- Hooks
@@ -71,23 +72,23 @@ const ReportPost = () => {
7172
// -------------------------------------------------------------------------------------
7273

7374
const [loading, setLoading] = useState<boolean>(false);
75+
const [alreadyReported, setAlreadyReported] = useState(false);
7476
const onSubmit = useCallback(async () => {
7577
setLoading(true);
7678
const result = await reportPost(message, [selectedReport.value]);
7779
setLoading(false);
7880

7981
if (result.isErr()) {
8082
if (isPostAlreadyReportedError(result.error)) {
81-
// TODO: Do something here - Maybe even nothing?
83+
setAlreadyReported(true);
8284
return;
8385
}
8486

85-
// TODO: Do something here -> waiting for design
86-
console.log('Error while reporting a post', result.error.message);
87+
toast.errorNoRetry(result.error.message);
8788
} else {
8889
setSuccessfulReport(true);
8990
}
90-
}, [reportPost, message, selectedReport.value]);
91+
}, [reportPost, message, selectedReport.value, toast]);
9192

9293
const successfulReportComponent = useMemo(() => {
9394
return (
@@ -109,56 +110,92 @@ const ReportPost = () => {
109110
theme.spacing.m,
110111
]);
111112

113+
const alreadyReportedComponent = useMemo(() => {
114+
return (
115+
<View style={styles.successfulReport}>
116+
<FastImage source={reportSuccessIcon} style={styles.reportIcon} />
117+
<Typography.H4 style={styles.headerText}>{t('already reported')}</Typography.H4>
118+
<Spacer paddingBottom={theme.spacing.m} />
119+
<Typography.Body5 style={styles.reportSuccessText}>
120+
{t('already reported message')}
121+
</Typography.Body5>
122+
</View>
123+
);
124+
}, [
125+
styles.headerText,
126+
styles.reportIcon,
127+
styles.reportSuccessText,
128+
styles.successfulReport,
129+
t,
130+
theme.spacing.m,
131+
]);
132+
133+
const standardComponent = useMemo(() => {
134+
return (
135+
<>
136+
<Typography.H4 style={styles.headerText}>{t('header')}</Typography.H4>
137+
<Spacer paddingBottom={10} />
138+
139+
<View>
140+
<CustomRadioGroup
141+
values={reportingReasons}
142+
selectedValue={selectedReport.index}
143+
onSelect={(index, value) => setSelectedReport({ value: parseInt(value, 10), index })}
144+
/>
145+
146+
<Spacer paddingBottom={theme.spacing.s} />
147+
<DTextInput
148+
editable={true}
149+
inputStyle={styles.messageInput}
150+
value={message}
151+
onChangeText={text => setMessage(text)}
152+
style={styles.textInput}
153+
multiline
154+
placeholder={t('message')}
155+
/>
156+
</View>
157+
<Spacer paddingVertical={30}>
158+
{loading ? (
159+
<View style={styles.loadingView}>
160+
<StyledSpinner />
161+
</View>
162+
) : (
163+
<Button
164+
size={44}
165+
backgroundColor={theme.colors.surfaceBlack}
166+
textColor={theme.colors.white}
167+
onPress={onSubmit}>
168+
{t('submit')}
169+
</Button>
170+
)}
171+
</Spacer>
172+
</>
173+
);
174+
}, [
175+
loading,
176+
message,
177+
onSubmit,
178+
reportingReasons,
179+
selectedReport.index,
180+
styles.headerText,
181+
styles.loadingView,
182+
styles.messageInput,
183+
styles.textInput,
184+
t,
185+
theme.colors.surfaceBlack,
186+
theme.colors.white,
187+
theme.spacing.s,
188+
]);
189+
112190
return (
113191
<KeyboardAvoidingView
114192
style={CommonStyles.flex[1]}
115193
keyboardVerticalOffset={Platform.OS === 'ios' ? -30 : 0}
116194
behavior={Platform.OS === 'ios' ? 'padding' : undefined}>
117195
<BottomUpModalWrapper goBack={goBack}>
118-
{successfulReport ? (
119-
successfulReportComponent
120-
) : (
121-
<>
122-
<Typography.H4 style={styles.headerText}>{t('header')}</Typography.H4>
123-
<Spacer paddingBottom={10} />
124-
125-
<View>
126-
<CustomRadioGroup
127-
values={reportingReasons}
128-
selectedValue={selectedReport.index}
129-
onSelect={(index, value) =>
130-
setSelectedReport({ value: parseInt(value, 10), index })
131-
}
132-
/>
133-
134-
<Spacer paddingBottom={theme.spacing.s} />
135-
<DTextInput
136-
editable={true}
137-
inputStyle={styles.messageInput}
138-
value={message}
139-
onChangeText={text => setMessage(text)}
140-
style={styles.textInput}
141-
multiline
142-
placeholder={t('message')}
143-
/>
144-
</View>
145-
<Spacer paddingVertical={30}>
146-
{loading ? (
147-
<View style={styles.loadingView}>
148-
<StyledSpinner />
149-
</View>
150-
) : (
151-
<Button
152-
size={44}
153-
backgroundColor={theme.colors.surfaceBlack}
154-
textColor={theme.colors.white}
155-
onPress={onSubmit}>
156-
{t('submit')}
157-
</Button>
158-
)}
159-
</Spacer>
160-
</>
161-
)}
196+
{successfulReport && successfulReportComponent}
197+
{alreadyReported && alreadyReportedComponent}
198+
{!successfulReport && !alreadyReported && standardComponent}
162199
</BottomUpModalWrapper>
163200
</KeyboardAvoidingView>
164201
);

0 commit comments

Comments
 (0)