Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat-mobile: add change profile setting #5481

Merged
merged 4 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mobile/features/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const features = {
enabled: false,
},
changeProfileName: {
enabled: false,
enabled: true,
},
},
security: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SETTINGS_ICON_SVG } from '@lib/auxiliary/icon'
import features from '../../../../features/features'
import {
ChangePasswordView,
ChangeProfileNameView,
ErrorLogView,
LanguageView,
DiagnosticsView,
Expand Down Expand Up @@ -29,6 +30,13 @@ export const SETTINGS_ROUTE_META = {
icon: SETTINGS_ICON_SVG[SettingsRoute.Language],
view: LanguageView,
},
[SettingsRoute.ChangeProfileName]: {
name: `views.settings.${SettingsRoute.ChangeProfileName}.title`,
category: SettingsCategory.General,
enabled: general?.[SettingsRoute.ChangeProfileName]?.enabled,
icon: SETTINGS_ICON_SVG[SettingsRoute.ChangeProfileName],
view: ChangeProfileNameView,
},
// Security
[SettingsRoute.ChangePassword]: {
name: `views.settings.${SettingsRoute.ChangePassword}.title`,
Expand All @@ -37,14 +45,14 @@ export const SETTINGS_ROUTE_META = {
icon: SETTINGS_ICON_SVG[SettingsRoute.ChangePassword],
view: ChangePasswordView,
},
// Advanced
[SettingsRoute.ErrorLog]: {
name: `views.settings.${SettingsRoute.ErrorLog}.title`,
category: SettingsCategory.Advanced,
enabled: advanced?.[SettingsRoute.ErrorLog]?.enabled,
icon: SETTINGS_ICON_SVG[SettingsRoute.ErrorLog],
view: ErrorLogView,
},
// Advanced
[SettingsRoute.Diagnostics]: {
name: `views.settings.${SettingsRoute.Diagnostics}.title`,
category: SettingsCategory.Advanced,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<script lang="typescript">
import { showAppNotification } from '@auxiliary/notification'
import { localize } from '@core/i18n'
import { activeProfile, updateActiveProfile, validateProfileName } from '@core/profile'
import { Button, ButtonSize, HTMLButtonType, Input, Text, TextType } from 'shared/components'

let newName = $activeProfile?.name
let error = ''

$: trimmedProfileName = newName.trim()
$: newName, (error = '')
$: disabled = invalidName(trimmedProfileName)

function onSubmitClick(): void {
try {
validateProfileName(trimmedProfileName)
updateActiveProfile({ name: trimmedProfileName })
showAppNotification({
type: 'info',
message: localize('views.settings.changeProfileName.success'),
})
} catch (err) {
return (error = err.message)
}
}

function invalidName(name: string): boolean {
const isSameName = name === $activeProfile?.name
const isTooShort = name?.length < 1
return isSameName || isTooShort
}
</script>

<form
class="h-full flex flex-col justify-between space-y-4"
id="form-change-profile-name"
on:submit|preventDefault={onSubmitClick}
>
<div class="flex flex-col space-y-4">
<Text type={TextType.p} secondary>
{localize('views.settings.changeProfileName.description')}
</Text>
<Input {error} placeholder={$activeProfile?.name} bind:value={newName} />
</div>
<Button size={ButtonSize.Medium} type={HTMLButtonType.Submit} {disabled}>
{localize('views.settings.changeProfileName.title')}
</Button>
</form>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as ChangePasswordView } from './ChangePasswordView.svelte'
export { default as ChangeProfileNameView } from './ChangeProfileNameView.svelte'
export { default as ErrorLogView } from './ErrorLogView.svelte'
export { default as DiagnosticsView } from './DiagnosticsView.svelte'
export { default as LanguageView } from './LanguageView.svelte'
Expand Down