Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 76 additions & 97 deletions src/components/input/argument_input/ArgumentInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import React, { useState, useEffect, useRef, lazy, Suspense } from "react";
import { FormattedMessage } from "react-intl";
import { useIntl } from "react-intl";
import { useLocation } from "react-router";
const SideModal = lazy(() => import("@logora/debate/modal/side_modal").then(m => ({ default: m.SideModal })));
const SideModal = lazy(() =>
import("@logora/debate/modal/side_modal").then((m) => ({
default: m.SideModal,
})),
);
import cx from "classnames";
import styles from "./ArgumentInput.module.scss";

Expand All @@ -27,7 +31,6 @@ export const ArgumentInput = ({
avatarSize = 48,
disabled = false,
positions = [],
disabledPositions = [],
groupId,
groupName,
groupType,
Expand Down Expand Up @@ -207,7 +210,6 @@ export const ArgumentInput = ({
onChooseSide={handleChooseSide}
positions={positions}
title={groupName}
disabledPositions={!isReply && disabledPositions}
isNeutral={
savedArgument &&
savedArgument.groupId == groupId &&
Expand All @@ -226,8 +228,7 @@ export const ArgumentInput = ({
if (
!positions ||
positions?.length === 0 ||
(!disabledPositions?.find((pos) => pos?.id === userPositionId) &&
userPositionId) ||
userPositionId ||
(isEditorOrModerator && isReply)
) {
submitArgument(isReply && isEditorOrModerator && positions[0]?.id);
Expand Down Expand Up @@ -289,64 +290,81 @@ export const ArgumentInput = ({
setSavedArgument(argumentToSave);
}
resetInputs();
api.create("messages", data).then((response) => {
if (response.data.success) {
if (parentId) {
onSubmit(response.data.data.resource);
toast(
intl.formatMessage({
id: "alert.argument_create",
defaultMessage: "Your contribution has been sent !",
}),
{
type: "success",
points: intl.formatMessage({
id: "alert.reply_gain",
defaultMessage: " ",
api
.create("messages", data)
.then((response) => {
if (response.data.success) {
if (parentId) {
onSubmit(response.data.data.resource);
toast(
intl.formatMessage({
id: "alert.argument_create",
defaultMessage: "Your contribution has been sent !",
}),
},
);
} else {
const argument = response.data.data.resource;
let listId = argumentListId;
if (userPosition && !isMobile) {
listId = `argumentList${argument.position.id}`;
{
type: "success",
points: intl.formatMessage({
id: "alert.reply_gain",
defaultMessage: " ",
}),
},
);
} else {
const argument = response.data.data.resource;
let listId = argumentListId;
if (userPosition && !isMobile) {
listId = `argumentList${argument.position.id}`;
}
onSubmit?.(
argumentContent,
positions.find((pos) => pos.id === userPosition) || null,
);
list.add(listId, [argument]);
toast(
intl.formatMessage({
id: "alert.argument_create",
defaultMessage: "Your contribution has been sent !",
}),
{
type: "success",
points: intl.formatMessage({
id: "alert.argument_create_gain",
defaultMessage: "Up to 10 eloquence points",
}),
category: "ARGUMENT",
contentKey:
currentUser.messages_count === 2
? "alert.third_argument"
: "alert.first_argument",
},
);
}
onSubmit?.(
argumentContent,
positions.find((pos) => pos.id === userPosition) || null,
);
list.add(listId, [argument]);
toast(
intl.formatMessage({
id: "alert.argument_create",
defaultMessage: "Your contribution has been sent !",
}),
{
type: "success",
points: intl.formatMessage({
id: "alert.argument_create_gain",
defaultMessage: "Up to 10 eloquence points",
if (typeof window !== "undefined") {
window.dispatchEvent(
new CustomEvent("logora:user_content:created", {
detail: {
content: response.data.data?.resource,
},
}),
category: "ARGUMENT",
contentKey:
currentUser.messages_count === 2
? "alert.third_argument"
: "alert.first_argument",
},
);
);
}
}
if (typeof window !== "undefined") {
window.dispatchEvent(
new CustomEvent("logora:user_content:created", {
detail: {
content: response.data.data?.resource,
},
}),
})
.catch((error) => {
if (error?.response?.status === 429) {
toast(
error?.response?.data?.error?.detail ||
intl.formatMessage({
id: "alert.argument_limit",
defaultMessage:
"You have reached your daily contribution limit for this debate.",
}),
{ type: "error" },
);
} else {
console.error(error);
}
}
});
});
}
};

Expand All @@ -365,9 +383,7 @@ export const ArgumentInput = ({
let listId = argumentListId;
if (editElement?.is_reply || isReply) {
const replyListId =
editElement?.message_id ||
editElement?.reply_to_id ||
parentId;
editElement?.message_id || editElement?.reply_to_id || parentId;
if (replyListId) {
listId = `argument_${replyListId}_reply_list`;
}
Expand Down Expand Up @@ -416,22 +432,6 @@ export const ArgumentInput = ({
}
};

const displayArgumentLimitWarning = () => {
const disabledPosition = disabledPositions.find(
(pos) => pos.id === userPositionId,
);
if (disabledPosition) {
return intl.formatMessage(
{
id: "info.argument_side_limit",
defaultMessage:
"You have reached the argument limit (10) for position {position}.",
},
{ position: disabledPosition.name },
);
}
};

return (
<div className={styles.inputContainer}>
{disabled && (
Expand Down Expand Up @@ -568,27 +568,6 @@ export const ArgumentInput = ({
))}
</div>
)}
{inputActivation &&
disabledPositions?.find(
(pos) => pos.id === userPositionId,
) && (
<div
className={cx(
styles.argumentInputWarning,
styles.disabledPositionWarning,
)}
>
<Icon
name="announcement"
className={styles.warningIcon}
height={20}
width={20}
/>
<div className={styles.argumentInputWarningText}>
{displayArgumentLimitWarning()}
</div>
</div>
)}
{inputActivation && userGuideUrl && !hideUserGuideLink && (
<div className={styles.guideMessage}>
<FormattedMessage
Expand Down
11 changes: 0 additions & 11 deletions src/components/input/argument_input/ArgumentInput.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const defaultArgs = {
groupName: debate.name,
groupType: "Group",
positions: debate.positions,
disabledPositions: [],
argumentListId: "argumentList",
positionId: debate.positions[0].id,
parentId: undefined,
Expand Down Expand Up @@ -116,7 +115,6 @@ export default {
userGuideUrl: { control: "text" },
groupType: { control: "text" },
positions: { control: "object" },
disabledPositions: { control: "object" },
onSubmit: { control: false },
parentId: { control: false },
argumentListId: { control: false },
Expand Down Expand Up @@ -151,15 +149,6 @@ export const ArgumentInputDisabled = {
},
};

export const ArgumentPositionDisabled = {
args: {
disabledPositions: [
{ id: debate.positions[0].id, name: debate.positions[0].name },
],
hideSourceAction: true,
},
};

export const DisabledArgumentInputForVisitors = {
render: (args) => (
<Providers
Expand Down
Loading