Skip to content

Commit

Permalink
feat(i18n): replace hardcoded string values for AdminFormNavbar (#7456)
Browse files Browse the repository at this point in the history
feat(i18n): add en-sg translations and types for admin-form-navbar, use translations in AdminFormNavbar

Co-authored-by: Ken Lee Shu Ming <[email protected]>
  • Loading branch information
helloitsxinyi and KenLSM authored Jul 8, 2024
1 parent b506433 commit a79f783
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import {
BiDotsHorizontalRounded,
BiShareAlt,
Expand Down Expand Up @@ -72,6 +73,7 @@ export const AdminFormNavbar = ({
handleShareButtonClick,
previewFormLink,
}: AdminFormNavbarProps): JSX.Element => {
const { t } = useTranslation()
const { ref, onMouseDown } = useDraggable<HTMLDivElement>()
const { isOpen, onClose, onOpen } = useDisclosure()
const { pathname } = useLocation()
Expand Down Expand Up @@ -182,7 +184,7 @@ export const AdminFormNavbar = ({
to={ADMINFORM_BUILD_SUBROUTE}
isActive={checkTabActive(ADMINFORM_BUILD_SUBROUTE)}
>
Create
{t('features.adminFormNavbar.tabs.create')}
</NavigationTab>
<NavigationTab
hidden={viewOnly}
Expand All @@ -197,7 +199,7 @@ export const AdminFormNavbar = ({
}
}}
>
Settings
{t('features.adminFormNavbar.tabs.settings')}
{shouldShowSettingsReddot ? (
<Icon
as={GoPrimitiveDot}
Expand All @@ -212,7 +214,7 @@ export const AdminFormNavbar = ({
to={ADMINFORM_RESULTS_SUBROUTE}
isActive={checkTabActive(ADMINFORM_RESULTS_SUBROUTE)}
>
Results
{t('features.adminFormNavbar.tabs.results')}
</NavigationTab>
</NavigationTabList>
<Flex
Expand All @@ -226,7 +228,7 @@ export const AdminFormNavbar = ({
>
<IconButton
display={{ base: 'flex', md: 'none' }}
aria-label="Form actions"
aria-label={t('features.adminFormNavbar.formActions')}
onClick={onOpen}
icon={<BiDotsHorizontalRounded />}
/>
Expand All @@ -235,26 +237,28 @@ export const AdminFormNavbar = ({
{renderLastModified}
</Flex>
<ButtonGroup spacing="0.5rem" isDisabled={!formInfo}>
<Tooltip label="Manage collaborators">
<Tooltip label={t('features.adminFormNavbar.manageCollaborators')}>
<IconButton
aria-label="Manage collaborators"
aria-label={t('features.adminFormNavbar.manageCollaborators')}
variant="outline"
onClick={handleAddCollabButtonClick}
icon={<BiUserPlus />}
/>
</Tooltip>
<Tooltip label="Preview form">
<Tooltip label={t('features.adminFormNavbar.previewForm')}>
<IconButton
as={ReactLink}
aria-label="Preview form"
aria-label={t('features.adminFormNavbar.previewForm')}
variant="outline"
to={previewFormLink}
target="_blank"
icon={<BiShow />}
/>
</Tooltip>
<Tooltip label="Share your form link">
<Button onClick={handleShareButtonClick}>Share</Button>
<Tooltip label={t('features.adminFormNavbar.shareBtn.tooltip')}>
<Button onClick={handleShareButtonClick}>
{t('features.adminFormNavbar.shareBtn.text')}
</Button>
</Tooltip>
</ButtonGroup>
</Box>
Expand All @@ -278,21 +282,21 @@ export const AdminFormNavbar = ({
{...mobileDrawerExtraButtonProps}
leftIcon={<BiShow fontSize="1.25rem" />}
>
Preview form
{t('features.adminFormNavbar.previewForm')}
</Button>
<Button
{...mobileDrawerExtraButtonProps}
onClick={handleShareButtonClick}
leftIcon={<BiShareAlt fontSize="1.25rem" />}
>
Share form link
{t('features.adminFormNavbar.shareBtn.textMobile')}
</Button>
<Button
{...mobileDrawerExtraButtonProps}
onClick={handleAddCollabButtonClick}
leftIcon={<BiUserPlus fontSize="1.25rem" />}
>
Manage collaborators
{t('features.adminFormNavbar.manageCollaborators')}
</Button>
</ButtonGroup>
</DrawerBody>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/i18n/locales/en-sg.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { enSG as adminFormNavbar } from './features/admin-form-navbar'
import { enSG as common } from './features/common'
import { enSG as login } from './features/login'
import { enSG as publicForm } from './features/public-form'
Expand All @@ -6,6 +7,7 @@ import { FallbackTranslation } from './types'
export const enSG: FallbackTranslation = {
translation: {
features: {
adminFormNavbar,
common,
login,
publicForm,
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/i18n/locales/features/admin-form-navbar/en-sg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { AdminFormNavbar } from '.'

export const enSG: AdminFormNavbar = {
tabs: {
create: 'Create',
settings: 'Settings',
results: 'Results',
routing: 'Routing',
},
manageCollaborators: 'Manage collaborators',
previewForm: 'Preview form',
formActions: 'Form actions',
shareBtn: {
text: 'Share',
textMobile: 'Share form link',
tooltip: 'Share your form link',
},
}
18 changes: 18 additions & 0 deletions frontend/src/i18n/locales/features/admin-form-navbar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export * from './en-sg'

export interface AdminFormNavbar {
tabs: {
create: string
settings: string
results: string
routing: string
}
manageCollaborators: string
previewForm: string
formActions: string
shareBtn: {
text: string
textMobile: string
tooltip: string
}
}
1 change: 1 addition & 0 deletions frontend/src/i18n/locales/features/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { type AdminFormNavbar } from './admin-form-navbar'
export { type Common } from './common'
export { type Login } from './login'
export { type PublicForm } from './public-form'
3 changes: 2 additions & 1 deletion frontend/src/i18n/locales/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Common, Login, PublicForm } from './features'
import { AdminFormNavbar, Common, Login, PublicForm } from './features'

interface Translation {
translation: {
features: {
adminFormNavbar?: AdminFormNavbar
common?: Common
publicForm?: PublicForm
login?: Login
Expand Down

0 comments on commit a79f783

Please sign in to comment.