Skip to content

Commit

Permalink
fix: add notification on copy action in technical user detail page (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
shahmargi12 authored Oct 16, 2024
1 parent 4a66c99 commit 38246d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/assets/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2377,7 +2377,8 @@
"exit": "exit",
"loading": "Loading...",
"unsubscribe": "Unsubscribe",
"edit": "Edit"
"edit": "Edit",
"copyInfoSuccessMessage": "Information erfolgreich kopiert"
},
"state": {
"enabled": "aktiv",
Expand Down
3 changes: 2 additions & 1 deletion src/assets/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,8 @@
"exit": "exit",
"loading": "Loading...",
"unsubscribe": "Unsubscribe",
"edit": "Edit"
"edit": "Edit",
"copyInfoSuccessMessage": "Information copied successfully"
},
"state": {
"enabled": "enabled",
Expand Down
4 changes: 4 additions & 0 deletions src/components/shared/basic/KeyValueView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

import { useState } from 'react'
import { Link } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Box } from '@mui/material'
import { Typography } from '@catena-x/portal-shared-components'
import ContentCopyIcon from '@mui/icons-material/ContentCopy'
import EditOutlinedIcon from '@mui/icons-material/EditOutlined'
import { success } from 'services/NotifyService'

type DataValue = string | number | JSX.Element | string[]

Expand Down Expand Up @@ -63,6 +65,7 @@ export const KeyValueView = ({
editLink,
}: KeyValueViewProps) => {
const [copied, setCopied] = useState<string>('')
const { t } = useTranslation()

const renderValueItem = (item: ValueItem) =>
item.copy ? (
Expand All @@ -79,6 +82,7 @@ export const KeyValueView = ({
const value = item.value ?? ''
await navigator.clipboard.writeText(value as string)
setCopied(value as string)
success(t('global.actions.copyInfoSuccessMessage'))
setTimeout(() => {
setCopied('')
}, 1000)
Expand Down
4 changes: 4 additions & 0 deletions src/components/shared/basic/ReadOnlyValue/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { useTranslation } from 'react-i18next'
import { Box } from '@mui/material'
import { Typography, Tooltips } from '@catena-x/portal-shared-components'
import type { IHashMap } from 'types/MainTypes'
import ContentCopyIcon from '@mui/icons-material/ContentCopy'
import HelpOutlineIcon from '@mui/icons-material/HelpOutline'
import { useState } from 'react'
import { success } from 'services/NotifyService'

const CopyValue = ({ value }: { value: string }) => {
const [copied, setCopied] = useState<boolean>(false)
const { t } = useTranslation()

return (
<Box
Expand All @@ -42,6 +45,7 @@ const CopyValue = ({ value }: { value: string }) => {
onClick={async () => {
await navigator.clipboard.writeText(value)
setCopied(true)
success(t('global.actions.copyInfoSuccessMessage'))
setTimeout(() => {
setCopied(false)
}, 1000)
Expand Down

0 comments on commit 38246d5

Please sign in to comment.