Skip to content

Commit

Permalink
refactor(requests): Refactor requests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
deo002 committed Jan 2, 2025
1 parent 433d9af commit 60d3441
Show file tree
Hide file tree
Showing 35 changed files with 1,058 additions and 1,023 deletions.
1 change: 1 addition & 0 deletions messages/de.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/Gruppe",
"default": {
"(n/a)": "",
"A package with the same name and version already exists": "Ein Paket mit demselben Namen und derselben Version ist bereits vorhanden",
Expand Down
1 change: 1 addition & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/Group",
"default": {
"(n/a)": "(n/a)",
"A package with the same name and version already exists": "A package with the same name and version already exists",
Expand Down
1 change: 1 addition & 0 deletions messages/es.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/Grupo",
"default": {
"(n/a)": "",
"A package with the same name and version already exists": "Ya existe un paquete con el mismo nombre y versión.",
Expand Down
1 change: 1 addition & 0 deletions messages/fr.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/Groupe",
"default": {
"(n/a)": "",
"A package with the same name and version already exists": "Un package avec le même nom et la même version existe déjà",
Expand Down
1 change: 1 addition & 0 deletions messages/ja.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/グループ",
"default": {
"(n/a)": "",
"A package with the same name and version already exists": "同じ名前とバージョンのパッケージがすでに存在します",
Expand Down
1 change: 1 addition & 0 deletions messages/ko.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/그룹",
"default": {
"(n/a)": "",
"A package with the same name and version already exists": "이름과 버전이 같은 패키지가 이미 존재합니다.",
Expand Down
1 change: 1 addition & 0 deletions messages/pt-BR.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/Grupo",
"default": {
"(n/a)": "",
"A package with the same name and version already exists": "Já existe um pacote com o mesmo nome e versão",
Expand Down
1 change: 1 addition & 0 deletions messages/vi.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/Nhóm",
"default": {
"(n/a)": "",
"A package with the same name and version already exists": "Đã tồn tại gói có cùng tên và phiên bản",
Expand Down
1 change: 1 addition & 0 deletions messages/zh-CN.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/组",
"default": {
"(n/a)": "",
"A package with the same name and version already exists": "已存在同名同版本的包",
Expand Down
1 change: 1 addition & 0 deletions messages/zh-TW.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BA-BL/Group": "BA-BL/組",
"default": {
"(n/a)": "",
"A package with the same name and version already exists": "已存在同名同版本的包",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,37 @@ import { ClearingRequestComments, Embedded, HttpStatus } from '@/object-types'
import MessageService from '@/services/message.service'
import { ApiUtils, CommonUtils } from '@/utils/index'
import parse from 'html-react-parser'
import { getSession, signOut } from 'next-auth/react'
import { getSession, signOut, useSession } from 'next-auth/react'
import { useTranslations } from 'next-intl'
import Link from 'next/link'
import { notFound } from 'next/navigation'
import { ReactElement, useCallback, useEffect, useState } from 'react'
import { ReactNode, useEffect, useState } from 'react'
import { Spinner } from 'react-bootstrap'

type EmbeddedClearingRequestComments = Embedded<ClearingRequestComments, 'sw360:comments'>

export default function ClearingComments({
clearingRequestId,
}: Readonly<{ clearingRequestId: string | undefined }>): ReactElement<any, any> | undefined {
}: Readonly<{ clearingRequestId: string | undefined }>): ReactNode | undefined {
const t = useTranslations('default')
const [loading, setLoading] = useState(true)
const [comments, setComments] = useState<Array<ClearingRequestComments>>([])
const [inputComment, setInputComment] = useState('')
const [commentPayload, setCommentPayload] = useState({
text: '',
})
const { status } = useSession()

const formatDate = (timestamp: number | undefined): string | null => {
if (timestamp == null) {
const formatDate = (timestamp: number | undefined) : string | null => {
if (timestamp === undefined) {
return null
}
const date = new Date(timestamp)
const dateISOString = date.toISOString()
return `${dateISOString.slice(0, 10)} ${dateISOString.slice(11, 19)}`
}

const fetchData = useCallback(async (url: string) => {
const fetchData = async (url: string) => {
const session = await getSession()
if (CommonUtils.isNullOrUndefined(session)) return signOut()
const response = await ApiUtils.GET(url, session.user.access_token)
Expand All @@ -55,7 +56,7 @@ export default function ClearingComments({
} else {
notFound()
}
}, [])
}

useEffect(() => {
setLoading(true)
Expand All @@ -75,7 +76,7 @@ export default function ClearingComments({
}
})
.catch((err) => console.error(err))
}, [fetchData])
}, [])

const updateInputField = (event: React.ChangeEvent<HTMLSelectElement | HTMLInputElement | HTMLTextAreaElement>) => {
setInputComment(event.target.value)
Expand Down Expand Up @@ -108,79 +109,80 @@ export default function ClearingComments({
if (status === 'unauthenticated') {
signOut()
} else {
return (
<>
{loading == false ? (
<table className={`table label-value-table ${styles['summary-table']}`}>
<thead>
<tr>
<th colSpan={2}>{t('Comments')}</th>
</tr>
</thead>
<tbody>
<tr>
<td colSpan={2}>
<input
className='form-control'
type='text'
name='text'
placeholder={t('Enter Comment')}
style={{ height: '50px', width: '100%', marginBottom: '20px' }}
value={inputComment}
onChange={updateInputField}
/>
<button
type='button'
className='btn btn-accept mb-2'
onClick={handleAddComment}
>
return (
<>
{loading == false ? (
<table className={`table label-value-table ${styles['summary-table']}`}>
<thead>
<tr>
<th colSpan={2}>{t('Comments')}</th>
</tr>
</thead>
<tbody>
<tr>
<td colSpan={2}>
<input
className='form-control'
type='text'
name='text'
placeholder={t('Enter Comment')}
style={{ height: '50px', width: '100%', marginBottom: '20px' }}
value={inputComment}
onChange={updateInputField}
/>
<button
type='button'
className='btn btn-accept mb-2'
onClick={() => void handleAddComment()}>
{t('Add Comment')}
</button>
</td>
</tr>
{comments.map((item: ClearingRequestComments) => (
<tr key={item.commentedOn}>
<td style={{ padding: '5px !important', width: '3%' }}>
<td style={{padding: '5px !important', width: '3%'}}>
<div>
{item._embedded?.commentingUser?.fullName
?.split(' ')
.map((word) => (word as string)[0])
.join('')
.toUpperCase() ?? ''}
{item._embedded?.commentingUser?.fullName?.split(' ')
.map(word => word[0])
.join('')
.toUpperCase() ?? ''
}
</div>
</td>
<td>
<div>
{item.autoGenerated != null && (
{ item.autoGenerated !== undefined &&
<>
*** <b>{t('This is auto-generated comment')}</b> ***
</>
)}
</div>
<div>
{item.text != null &&
parse(
item.text
.replace(/<li>/g, '<li style="margin-left:10px;">')
.replace(/\n/g, '<br />&emsp;&emsp;'),
)}
}
</div>
<div>
{
<>
-- by &thinsp;{' '}
{
item.text !== undefined && parse(
item.text.replace(/<li>/g, '<li style="margin-left:10px;">')
.replace(/\n/g, '<br />&emsp;&emsp;')
)
}
</div>
<div>
{<>
-- by &thinsp; {
<i>
<Link
className='text-link'
href={`mailto:${item.commentedBy}`} >
<b>
{item._embedded?.commentingUser?.fullName}
</b>
</Link>
</i>
} &thinsp; on &thinsp;
<i>
<Link
className='text-link'
href={`mailto:${item.commentedBy}`}
>
<b>{item._embedded?.commentingUser?.fullName}</b>
</Link>
{
formatDate(item.commentedOn)
}
</i>
}{' '}
&thinsp; on &thinsp;
<i>{formatDate(item.commentedOn)}</i>
</>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

import { ClearingRequestDetails } from '@/object-types'
import { signOut, useSession } from 'next-auth/react'
import { ReactNode } from 'react'
import { useTranslations } from 'next-intl'
import Link from 'next/link'
import { ReactElement } from 'react'

interface ClearingRequestDataMap {
[key: string]: string
Expand All @@ -23,7 +23,7 @@ interface Props {
data: ClearingRequestDetails | undefined
}

export default function ClearingDecision({ data }: Readonly<Props>): ReactElement<any, any> | undefined {
export default function ClearingDecision({ data }: Readonly<Props>): ReactNode | undefined {
const t = useTranslations('default')
const { status } = useSession()
const clearingRequestStatus: ClearingRequestDataMap = {
Expand Down Expand Up @@ -70,11 +70,9 @@ export default function ClearingDecision({ data }: Readonly<Props>): ReactElemen
<tr>
<td>{t('Clearing Team')}:</td>
<td>
{data?.clearingTeam != null ? (
<Link href={`mailto:${data.clearingTeam}`}>{data.clearingTeamName}</Link>
) : (
''
)}
{data?.clearingTeam !== undefined
? <Link href={`mailto:${data.clearingTeam}`}>{data.clearingTeamName}</Link>
: ''}
</td>
</tr>
<tr>
Expand Down
Loading

0 comments on commit 60d3441

Please sign in to comment.