Skip to content

Commit

Permalink
speedDial. Avoid speedDials operators to be set as favourite
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 committed Oct 30, 2024
1 parent d31f826 commit 9b93cd4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 22 deletions.
41 changes: 21 additions & 20 deletions components/history/ShowHistoryDrawerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LastCallsDrawerTable } from './LastCallsDrawerTable'
import { startOfDay, subDays } from 'date-fns'
import { useSelector } from 'react-redux'
import { RootState } from '../../store'
import { t } from 'i18next'

export interface ShowHistoryDrawerContentProps extends ComponentPropsWithRef<'div'> {
config: any
Expand All @@ -24,7 +25,7 @@ function checkTitle(config: any) {
<Avatar size='large' placeholderType='person' />
</div>
<div>
<h2 className='text-xl font-medium text-gray-700 dark:text-gray-200'>{config.name}</h2>
<h2 className='text-xl font-medium text-gray-700 dark:text-gray-200'>{config?.name}</h2>
</div>
</div>
)
Expand All @@ -35,7 +36,7 @@ function checkTitle(config: any) {
<Avatar size='large' placeholderType='company' />
</div>
<div className='flex-shrink-0 mr-4'>
<h2 className='text-xl font-medium text-gray-700 dark:text-gray-200'>{config.company}</h2>
<h2 className='text-xl font-medium text-gray-700 dark:text-gray-200'>{config?.company}</h2>
</div>
</div>
)
Expand All @@ -46,7 +47,7 @@ function checkTitle(config: any) {
<Avatar size='large' placeholderType='person' />
</div>
<div>
<h2 className='text-xl font-medium text-gray-700 dark:text-gray-200'>{config.number}</h2>
<h2 className='text-xl font-medium text-gray-700 dark:text-gray-200'>{config?.number}</h2>
</div>
</div>
)
Expand All @@ -64,7 +65,7 @@ export const ShowHistoryDrawerContent = forwardRef<
<div className='bg-white dark:bg-gray-900 pt-6 px-6'>
<div className='flex items-center justify-between'>
<div className='text-lg dark:text-gray-200 text-gray-700 font-medium'>
History details
{t('Common.History details')}
</div>
<div className='flex items-center h-7'>
<SideDrawerCloseIcon className='p-0.5' />
Expand All @@ -84,12 +85,12 @@ export const ShowHistoryDrawerContent = forwardRef<
<div>
<Button variant='primary' className='mr-2' onClick={() => callUser(config)}>
<FontAwesomeIcon icon={faPhone} className='h-4 w-4 xl:mr-2' />
<span className='hidden xl:inline-block'>Call</span>
<span className='sr-only'>Call</span>
<span className='hidden xl:inline-block'>{t('Common.Call')}</span>
<span className='sr-only'>{t('Common.Call')}</span>
</Button>
</div>
<div>
{!config.name && !config.company && (
{!config?.name && !config?.company && (
<Button
variant='white'
className='mr-2'
Expand All @@ -99,31 +100,31 @@ export const ShowHistoryDrawerContent = forwardRef<
icon={faPlus}
className='h-4 w-4 xl:mr-2 text-gray-500 dark:text-gray-400'
/>
<span className='hidden xl:inline-block'>Add to phonebook</span>
<span className='sr-only'>Add to phonebook</span>
<span className='hidden xl:inline-block'>{t('Common.Add to phonebook')}</span>
<span className='sr-only'>{t('Common.Add to phonebook')}</span>
</Button>
)}
</div>
</div>
<div>
{config.company && (
{config?.company && (
<div className='mt-6 border-t border-gray-200 dark:border-gray-700'>
<dl className='sm:divide-y sm:divide-gray-200 dark:sm:divide-gray-700'>
{/* Company name */}
<div className='py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:py-5'>
<dt className='text-sm font-medium text-gray-500 dark:text-gray-400'>
Company name
{t('Common.Company name')}
</dt>
<dd className='mt-1 text-sm text-gray-900 dark:text-gray-100 sm:col-span-2 sm:mt-0'>
<div className='flex items-center text-sm'>
<span className='truncate '>{config.company}</span>
<span className='truncate '>{config?.company}</span>
</div>
</dd>
</div>
{/* Phone number */}
<div className='py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:py-5'>
<dt className='text-sm font-medium text-gray-500 dark:text-gray-400'>
Phone number
{t('Common.Phone number')}
</dt>
<dd className='mt-1 text-sm text-gray-900 dark:text-gray-100 sm:col-span-2 sm:mt-0'>
<div className='flex items-center text-sm text-primary dark:text-primaryDark'>
Expand All @@ -133,21 +134,21 @@ export const ShowHistoryDrawerContent = forwardRef<
aria-hidden='true'
/>
<span className='truncate cursor-pointer hover:underline'>
{config.number}
{config?.number}
</span>
</div>
</dd>
</div>
</dl>
</div>
)}
{config.name && !config.company && config.number && (
{config?.name && !config?.company && config?.number && (
<div className='mt-6 border-t border-gray-200 dark:border-gray-700'>
<dl className='sm:divide-y sm:divide-gray-200 dark:sm:divide-gray-700'>
{/* Phone number */}
<div className='py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:py-5'>
<dt className='text-sm font-medium text-gray-500 dark:text-gray-400'>
Phone number
{t('Common.Phone number')}
</dt>
<dd className='mt-1 text-sm text-gray-900 dark:text-gray-100 sm:col-span-2 sm:mt-0'>
<div className='flex items-center text-sm text-primary dark:text-primaryDark'>
Expand All @@ -157,7 +158,7 @@ export const ShowHistoryDrawerContent = forwardRef<
aria-hidden='true'
/>
<span className='truncate cursor-pointer hover:underline'>
{config.number}
{config?.number}
</span>
</div>
</dd>
Expand All @@ -168,12 +169,12 @@ export const ShowHistoryDrawerContent = forwardRef<
</div>

{/* last calls */}
{profile.macro_permissions?.cdr?.permissions?.ad_cdr?.value && (
{profile?.macro_permissions?.cdr?.permissions?.ad_cdr?.value && (
<LastCallsDrawerTable
callType={config.callType}
callType={config?.callType}
dateFrom={startOfDay(subDays(new Date(), 7))}
dateTo={new Date()}
phoneNumbers={[config.number]}
phoneNumbers={[config?.number]}
limit={10}
/>
)}
Expand Down
12 changes: 10 additions & 2 deletions lib/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,16 @@ export const retrieveAvatars = async (authStore: any) => {
export const retrieveFavoriteOperators = async (authStore: any, operatorObject: any) => {
store.dispatch.operators.setFavoritesLoaded(false)
const speedDials = await getSpeedDials()

// Avoid to add a favorite operator if you add it in the speed dials form
const speedDialMap: any = speedDials.reduce((acc: any, speedDial: any) => {
acc[speedDial?.name] = { id: speedDial?.id }
if (speedDial?.notes === 'speeddial-favorite') {
acc[speedDial?.name] = { id: speedDial?.id }
}
return acc
}, {})

// Retrieve the favorite operators from the speed dials Object
store.dispatch.operators.setFavoritesObjectComplete(speedDialMap)

const favoriteOperatorsLocalStorage =
Expand Down Expand Up @@ -307,7 +313,9 @@ export const retrieveFavoriteOperators = async (authStore: any, operatorObject:
clearPreference('favoriteOperators', authStore?.username)
}

const speedDialOwners = speedDials.map((speedDial: any) => speedDial?.name)
const speedDialOwners = speedDials
.filter((speedDial: any) => speedDial?.notes === 'speeddial-favorite')
.map((speedDial: any) => speedDial?.name)

store.dispatch.operators.setFavorites(speedDialOwners)
store.dispatch.operators.setFavoritesLoaded(true)
Expand Down
20 changes: 20 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"Save": "Save",
"Try changing your search filters": "Try changing your search filters",
"Phone number": "Phone number",
"Company name": "Company name",
"Call": "Call",
"History details": "History details",
"Add to phonebook": "Add to phonebook",
"time_distance_ago": "{{ timeDistance }} ago",
"0 minutes ago": "0 minutes ago",
"Add to favorites": "Add to favorites",
Expand Down Expand Up @@ -878,5 +882,21 @@
},
"Transfer": {
"No users found": "No users found"
},
"Errors": {
"browser_permissions": "Browser Permissions Error",
"user_permissions": "User Permissions Error",
"unknown_media_permissions": "Unknown Media Permissions Error",
"webrtc_down": "WebRTC Down",
"socket_down": "Socket Down",
"busy_camera": "Busy Camera",
"call_transfered": "Call Transferred Successfully",
"The browser doesn't have permission to access camera or microphone.": "The browser doesn't have permission to access camera or microphone.",
"You must accept audio and video permissions.": "You must accept audio and video permissions.",
"Web Phone can't access audio or camera on this device.": "Web Phone can't access audio or camera on this device.",
"Web Phone connection is down.": "Web Phone connection is down.",
"Server connection is down.": "Server connection is down.",
"Camera is used by another application.": "Camera is used by another application.",
"Call transferred successfully.": "Call transferred successfully."
}
}
20 changes: 20 additions & 0 deletions public/locales/it/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"Warning": "Attenzione",
"Calling": "In chiamata",
"Phone number": "Numero telefonico",
"Company name": "Nome azienda",
"Call": "Chiama",
"History details": "Dettagli storico",
"Add to phonebook": "Aggiungi alla rubrica",
"Operators": "Operatori",
"Phonebook": "Rubrica",
"History": "Storico",
Expand Down Expand Up @@ -855,5 +859,21 @@
},
"Transfer": {
"No users found": "Nessun utente trovato"
},
"Errors": {
"browser_permissions": "Errore di autorizzazione",
"user_permissions": "Errore di autorizzazione",
"unknown_media_permissions": "Errore di autorizzazione",
"webrtc_down": "WebRTC non disponibile",
"socket_down": "Socket non disponibile",
"busy_camera": "Camera occupata",
"call_transfered": "Chiamata trasferita con successo",
"The browser doesn't have permission to access camera or microphone.": "Il browser non ha il permesso di accedere alla fotocamera o al microfono.",
"You must accept audio and video permissions.": "Devi accettare i permessi audio e video.",
"Web Phone can't access audio or camera on this device.": "Il Web Phone non può accedere all'audio o alla fotocamera su questo dispositivo.",
"Web Phone connection is down.": "La connessione del Web Phone è interrotta.",
"Server connection is down.": "La connessione al server è interrotta.",
"Camera is used by another application.": "La fotocamera è utilizzata da un'altra applicazione.",
"Call transferred successfully.": "Chiamata trasferita con successo."
}
}

0 comments on commit 9b93cd4

Please sign in to comment.