Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated AcceptCooperationClosing #2993

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
8 changes: 7 additions & 1 deletion src/constants/translations/en/cooperation-details.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@
"closingMessage1": " started a closing process for the current cooperation. You will have ",
"accessDuration": "1 month of access",
"closingMessage2": " to study materials after the cooperation has been closed.",
"acceptBtn": "Accept"
"acceptBtn": "Accept",
"declineBtn": "Decline",
"submitBtn": "Submit",
"inputFieldPlaceholder": "Enter your reason for declining",
"InputFieldLabel": "Please provide a reason for declining to close the cooperation.",
"inputError": "This field is required.",
"submitMessage": "Your reason has been successfully submitted to the opposite party."
}
8 changes: 7 additions & 1 deletion src/constants/translations/uk/cooperation-details.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@
"closingMessage1": " ініціював(-ла) процес припинення співпраці. У вас залишиться доступ до матеріалів поточної співпраці протягом ",
"accessDuration": "1 місяця",
"closingMessage2": " з моменту закриття.",
"acceptBtn": "Прийняти"
"acceptBtn": "Прийняти",
"declineBtn": "Відхилити",
"submitBtn": "Підтвердити",
"inputFieldPlaceholder": "Введіть причину відмови",
"InputFieldLabel": "Будь ласка, вкажіть причину відмови від закриття співпраці.",
"inputError": "Це поле є обов'язковим для заповнення.",
"submitMessage": "Вашу причину було успішно надіслано протилежній стороні."
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import palette from '~/styles/app-theme/app.pallete'

export const styles = {
boldText: {
fontWeight: 500
},
inputBox: {
display: 'flex',
flexDirection: 'column',
gap: '10px',
mb: '8px'
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
},
inputField: {
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
display: 'flex',
gap: '16px',
width: '100%',
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
height: '50px'
},
input: {
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
flex: 1
},
textGray: {
color: palette.basic.darkGray
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,81 @@
import { ErrorOutlineRounded } from '@mui/icons-material'
import { Typography } from '@mui/material'
import { Box, Typography } from '@mui/material'
import { useTranslation } from 'react-i18next'
import CooperationActionBanner from '~/containers/my-cooperations/cooperation-action-banner/CooperationActionBanner'
import Button from '~/design-system/components/button/Button'

import { styles } from './AcceptCooperationClosing.styles'
import { useState } from 'react'
import InputField from '~/design-system/components/input-field/InputField'
import { InputFieldVariantEnum } from '~/design-system/components/input-field/InputField.constants'
import useForm from '~/hooks/use-form'

interface AcceptCooperationClosureProps {
user: string
onAccept: () => void
onReasonSubmit: (reason: string) => void
}

const AcceptCooperationClosing: React.FC<AcceptCooperationClosureProps> = ({
user,
onAccept
onAccept,
onReasonSubmit
}) => {
const { t } = useTranslation()
const [isInputShown, setIsInputShown] = useState<boolean>(false)
const [isReasonSubmitted, setIsReasonSubmitted] = useState<boolean>(false)

const handleDecline = () => {
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
setIsInputShown(true)
}

const {
data,
errors,
trigger,
handleInputChange,
handleNonInputValueChange,
handleSubmit
} = useForm({
initialValues: { declineReason: '' },
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
validations: {
declineReason: (value) =>
value ? '' : t('cooperationDetailsPage.inputError')
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
},
onSubmit: (formData) => {
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
if (formData) {
onReasonSubmit(formData.declineReason)
}
}
})

const handleReasonSubmit = () => {
const isValid = trigger('declineReason')
handleSubmit()
if (isValid && !errors.declineReason) {
setIsReasonSubmitted(true)
setIsInputShown(false)
}
}

const isSubmitMessageShown =
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
isReasonSubmitted && !errors.declineReason ? (
<Typography sx={styles.textGray}>
{t('cooperationDetailsPage.submitMessage')}
</Typography>
) : null

return (
<CooperationActionBanner
actionButtons={
<Button color='tonal-error' onClick={onAccept} size='xs'>
{t('cooperationDetailsPage.acceptBtn')}
</Button>
<>
<Button color='tonal-error' onClick={onAccept} size='xs'>
{t('cooperationDetailsPage.acceptBtn')}
</Button>
<Button onClick={handleDecline} size='xs'>
{t('cooperationDetailsPage.declineBtn')}
</Button>
</>
}
description={
<>
Expand All @@ -38,7 +91,32 @@ const AcceptCooperationClosing: React.FC<AcceptCooperationClosureProps> = ({
}
icon={<ErrorOutlineRounded />}
title={t('titles.acceptCooperationClosing')}
/>
>
{isInputShown ? (
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
<Box sx={styles.inputBox}>
<Typography sx={styles.textGray}>
{t('cooperationDetailsPage.InputFieldLabel')}{' '}
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
</Typography>
<Box sx={styles.inputField}>
<InputField
error={!!errors.declineReason}
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
helperText={errors.declineReason}
onChange={handleInputChange('declineReason')}
onClear={() => handleNonInputValueChange('declineReason', '')}
ShadowOfTheSpace marked this conversation as resolved.
Show resolved Hide resolved
placeholder={t('cooperationDetailsPage.inputFieldPlaceholder')}
sx={styles.input}
value={data.declineReason}
variant={InputFieldVariantEnum.Outlined}
></InputField>
<Button color='tonal-error' onClick={handleReasonSubmit} size='md'>
{t('cooperationDetailsPage.submitBtn')}
</Button>
</Box>
</Box>
) : (
isSubmitMessageShown
)}
</CooperationActionBanner>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const CooperationDetails = () => {
const acceptClosingProcess = !isClosed && (
<AcceptCooperationClosing
onAccept={handleCooperationCloseAccept}
onReasonSubmit={() => {}}
user={closeCooperationInitiator.firstName}
/>
)
Expand Down
Loading