Update profile visibility toggle: replace modal with direct API call and toast notifications; remove unused setShowVisibilityModal prop

This commit is contained in:
MartinBraquet
2026-05-11 12:42:19 +02:00
parent 7a184cdf99
commit da871bfe7a
2 changed files with 22 additions and 13 deletions

View File

@@ -23,6 +23,7 @@ import {linkClass} from 'web/components/widgets/site-link'
import {StarButton} from 'web/components/widgets/star-button'
import {Tooltip} from 'web/components/widgets/tooltip'
import {useUser} from 'web/hooks/use-user'
import {updateProfile} from 'web/lib/api'
import {useT} from 'web/lib/locale'
import {track} from 'web/lib/service/analytics'
import {disableProfile} from 'web/lib/util/disable'
@@ -175,17 +176,8 @@ export function ProfileHeaderActions(props: {
showMessageButton: boolean
refreshProfile: () => void
isHiddenFromMe: boolean | undefined
setShowVisibilityModal: (show: boolean) => void
}) {
const {
user,
profile,
starredUserIds,
refreshStars,
showMessageButton,
refreshProfile,
setShowVisibilityModal,
} = props
const {user, profile, starredUserIds, refreshStars, showMessageButton, refreshProfile} = props
const currentUser = useUser()
const isCurrentUser = currentUser?.id === user.id
const disabled = profile.disabled
@@ -252,7 +244,26 @@ export function ProfileHeaderActions(props: {
) : (
<LockClosedIcon className="h-4 w-4" />
),
onClick: () => setShowVisibilityModal(true),
onClick: async () => {
toast
.promise(
updateProfile({
visibility: profile.visibility === 'member' ? 'public' : 'member',
}),
{
loading: 'Loading...',
success: 'Success!',
error:
'Failed to update profile visibility. Try again later or contact support.',
},
)
.then(() => {
refreshProfile()
})
.catch(() => {
// noop
})
},
},
{
name: disabled

View File

@@ -103,8 +103,6 @@ export function ProfileInfo(props: {
showMessageButton={showMessageButton}
refreshProfile={refreshProfile}
isHiddenFromMe={isHiddenFromMe}
// no-op: the visibility modal lives inside ProfileHeader below
setShowVisibilityModal={() => {}}
/>
</div>
</div>