-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Implementing text when saving scopes
- Loading branch information
Showing
6 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...ngsModal/components/Tabs/Maskinporten/ScopeListContainer/SaveStatus/SaveStatus.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.savingContainer { | ||
display: flex; | ||
align-items: center; | ||
gap: var(--fds-spacing-1); | ||
margin-top: var(--fds-spacing-4); | ||
} | ||
|
||
.savedIcon { | ||
font-size: var(--fds-sizing-8); | ||
} |
55 changes: 55 additions & 0 deletions
55
...tingsModal/components/Tabs/Maskinporten/ScopeListContainer/SaveStatus/SaveStatus.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { SaveStatus, type SaveStatusProps } from './SaveStatus'; | ||
import { textMock } from '@studio/testing/mocks/i18nMock'; | ||
|
||
const defaultProps: SaveStatusProps = { | ||
isPending: true, | ||
isSaved: true, | ||
}; | ||
|
||
describe('SaveStatus', () => { | ||
it('should render pending status with spinner', () => { | ||
renderSaveStatus({ | ||
componentProps: { | ||
isSaved: false, | ||
}, | ||
}); | ||
|
||
expect( | ||
screen.getByText(textMock('settings_modal.maskinporten_tab_save_scopes_pending')), | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
screen.getByTitle(textMock('settings_modal.maskinporten_tab_save_scopes_pending_spinner')), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render saved status with checkmark icon', () => { | ||
renderSaveStatus({ | ||
componentProps: { | ||
isPending: false, | ||
}, | ||
}); | ||
expect( | ||
screen.getByText(textMock('settings_modal.maskinporten_tab_save_scopes_complete')), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render nothing when neither pending nor saved', () => { | ||
const { container } = renderSaveStatus({ | ||
componentProps: { | ||
isPending: false, | ||
isSaved: false, | ||
}, | ||
}); | ||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
}); | ||
|
||
type Props = { | ||
componentProps: Partial<SaveStatusProps>; | ||
}; | ||
const renderSaveStatus = (props: Partial<Props> = {}) => { | ||
return render(<SaveStatus {...defaultProps} {...props.componentProps} />); | ||
}; |
50 changes: 50 additions & 0 deletions
50
...n/SettingsModal/components/Tabs/Maskinporten/ScopeListContainer/SaveStatus/SaveStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { type ReactElement } from 'react'; | ||
import classes from './SaveStatus.module.css'; | ||
import { StudioParagraph, StudioSpinner } from '@studio/components'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { CheckmarkIcon } from '@studio/icons'; | ||
|
||
export type SaveStatusProps = { | ||
isPending: boolean; | ||
isSaved: boolean; | ||
}; | ||
|
||
export const SaveStatus = ({ isPending, isSaved }: SaveStatusProps): ReactElement => { | ||
const { t } = useTranslation(); | ||
|
||
if (isPending) { | ||
return ( | ||
<SaveStatusContent | ||
text={t('settings_modal.maskinporten_tab_save_scopes_pending')} | ||
isPending | ||
/> | ||
); | ||
} | ||
if (isSaved) { | ||
return <SaveStatusContent text={t('settings_modal.maskinporten_tab_save_scopes_complete')} />; | ||
} | ||
return null; | ||
}; | ||
|
||
type SaveStatusContentProps = { | ||
text: string; | ||
isPending?: boolean; | ||
}; | ||
|
||
const SaveStatusContent = ({ text, isPending = false }: SaveStatusContentProps): ReactElement => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<div className={classes.savingContainer}> | ||
<StudioParagraph size='sm'>{text}</StudioParagraph> | ||
{isPending ? ( | ||
<StudioSpinner | ||
spinnerTitle={t('settings_modal.maskinporten_tab_save_scopes_pending_spinner')} | ||
size='sm' | ||
/> | ||
) : ( | ||
<CheckmarkIcon className={classes.savedIcon} /> | ||
)} | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...lButton/SettingsModal/components/Tabs/Maskinporten/ScopeListContainer/SaveStatus/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SaveStatus } from './SaveStatus'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters