Skip to content

Commit 0a41ebb

Browse files
committed
Add an option to disable your profile
1 parent 476fe16 commit 0a41ebb

File tree

8 files changed

+65
-7
lines changed

8 files changed

+65
-7
lines changed

backend/api/src/get-profiles.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export const loadProfiles = async (props: profileQueryType) => {
118118
(has_kids == 0 && !l.has_kids) ||
119119
(l.has_kids && l.has_kids > 0)) &&
120120
(is_smoker === undefined || l.is_smoker === is_smoker) &&
121+
(!l.disabled) &&
121122
(l.id.toString() != skipId) &&
122123
(!geodbCityIds ||
123124
(l.geodb_city_id && geodbCityIds.includes(l.geodb_city_id))) &&
@@ -149,6 +150,7 @@ export const loadProfiles = async (props: profileQueryType) => {
149150
join('users on users.id = profiles.user_id'),
150151
leftJoin(userActivityJoin),
151152
where('looking_for_matches = true'),
153+
where(`profiles.disabled != true`),
152154
// where(`pinned_url is not null and pinned_url != ''`),
153155
where(
154156
`(data->>'isBannedFromPosting' != 'true' or data->>'isBannedFromPosting' is null)`

backend/email/emails/functions/mock.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const sinclairProfile: ProfileRow = {
3939
religion: [],
4040
pref_relation_styles: ['friendship'],
4141
pref_romantic_styles: ['poly', 'open', 'mono'],
42+
disabled: false,
4243
wants_kids_strength: 3,
4344
looking_for_matches: true,
4445
visibility: 'public',
@@ -137,6 +138,7 @@ export const jamesProfile: ProfileRow = {
137138
city: 'San Francisco',
138139
gender: 'male',
139140
pref_gender: ['female'],
141+
disabled: false,
140142
pref_age_min: 22,
141143
pref_age_max: 32,
142144
religion: [],

backend/supabase/profiles.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
DO $$
32
BEGIN
43
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'profile_visibility') THEN
@@ -53,6 +52,7 @@ CREATE TABLE IF NOT EXISTS profiles (
5352
visibility profile_visibility DEFAULT 'member'::profile_visibility NOT NULL,
5453
wants_kids_strength INTEGER DEFAULT 0 NOT NULL,
5554
website TEXT,
55+
disabled BOOLEAN DEFAULT FALSE NOT NULL,
5656
CONSTRAINT profiles_pkey PRIMARY KEY (id)
5757
);
5858

common/src/api/zod-types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,18 @@ const optionalProfilesSchema = z.object({
8282
ethnicity: z.array(z.string()).optional(),
8383
born_in_location: z.string().optional(),
8484
height_in_inches: z.number().optional(),
85-
has_pets: zBoolean.optional().optional(),
85+
has_pets: zBoolean.optional(),
8686
education_level: z.string().optional(),
87-
is_smoker: zBoolean.optional().optional(),
87+
is_smoker: zBoolean.optional(),
88+
disabled: zBoolean.optional(),
8889
drinks_per_month: z.number().min(0).optional(),
8990
diet: z.array(z.string()).optional(),
9091
has_kids: z.number().min(0).optional(),
9192
university: z.string().optional(),
9293
occupation_title: z.string().optional(),
9394
occupation: z.string().optional(),
9495
company: z.string().optional(),
95-
comments_enabled: zBoolean.optional().optional(),
96+
comments_enabled: zBoolean.optional(),
9697
website: z.string().optional(),
9798
bio: contentSchema.optional().nullable(),
9899
twitter: z.string().optional(),

common/src/supabase/schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ export type Database = {
541541
country: string | null
542542
created_time: string
543543
diet: string[] | null
544+
disabled: boolean
544545
drinks_per_month: number | null
545546
education_level: string | null
546547
ethnicity: string[] | null
@@ -591,6 +592,7 @@ export type Database = {
591592
country?: string | null
592593
created_time?: string
593594
diet?: string[] | null
595+
disabled?: boolean
594596
drinks_per_month?: number | null
595597
education_level?: string | null
596598
ethnicity?: string[] | null
@@ -641,6 +643,7 @@ export type Database = {
641643
country?: string | null
642644
created_time?: string
643645
diet?: string[] | null
646+
disabled?: boolean
644647
drinks_per_month?: number | null
645648
education_level?: string | null
646649
ethnicity?: string[] | null

web/components/profile/profile-header.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {VisibilityConfirmationModal} from './visibility-confirmation-modal'
2323
import {deleteAccount} from "web/lib/util/delete";
2424
import toast from "react-hot-toast";
2525
import {StarButton} from "web/components/widgets/star-button";
26+
import {disableProfile} from "web/lib/util/disable";
2627

2728
export default function ProfileHeader(props: {
2829
user: User
@@ -47,12 +48,14 @@ export default function ProfileHeader(props: {
4748
const currentUser = useUser()
4849
const isCurrentUser = currentUser?.id === user.id
4950
const [showVisibilityModal, setShowVisibilityModal] = useState(false)
51+
const disabled = profile.disabled
5052

5153
console.debug('ProfileProfileHeader', {user, profile, userActivity, currentUser})
5254

5355
return (
5456
<Col className="w-full">
5557
<Row className={clsx('flex-wrap justify-between gap-2 py-1')}>
58+
{currentUser && isCurrentUser && disabled && <div className="text-red-500">You disabled your profile, so no one else can access it.</div>}
5659
<Row className="items-center gap-1">
5760
<Col className="gap-1">
5861
<Row className="items-center gap-1 text-xl">
@@ -135,6 +138,33 @@ export default function ProfileHeader(props: {
135138
}
136139
},
137140
},
141+
{
142+
name: disabled ? 'Enable profile' : 'Disable profile',
143+
icon: null,
144+
onClick: async () => {
145+
const confirmed = true // confirm(
146+
// 'Are you sure you want to disable your profile? This will hide your profile from searches and listings..'
147+
// )
148+
if (confirmed) {
149+
toast
150+
.promise(disableProfile(!disabled), {
151+
loading: disabled ? 'Enabling profile...' : 'Disabling profile...',
152+
success: () => {
153+
return `Profile ${disabled ? 'enabled' : 'disabled'}`
154+
},
155+
error: () => {
156+
return `Failed to ${disabled ? 'enable' : 'disable'} profile`
157+
},
158+
})
159+
.then(() => {
160+
refreshProfile()
161+
})
162+
.catch(() => {
163+
// return false
164+
})
165+
}
166+
},
167+
},
138168
]}
139169
/>
140170
</Row>

web/lib/util/disable.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {track} from "web/lib/service/analytics";
2+
import {updateProfile} from "web/lib/api";
3+
4+
export async function disableProfile(disabled: boolean) {
5+
track(`disable profile ${disabled ? 'on' : 'off'}`)
6+
await updateProfile({disabled: disabled})
7+
}

web/pages/[username]/index.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,32 @@ function UserPageInner(props: ActiveUserPageProps) {
158158
const fromSignup = query.fromSignup === 'true'
159159

160160
const currentUser = useUser()
161-
// const isCurrentUser = currentUser?.id === user?.id
161+
const isCurrentUser = currentUser?.id === user?.id
162162

163163
useSaveReferral(currentUser, {defaultReferrerUsername: username})
164-
useTracking('viewprofile', {username: user?.username})
164+
useTracking('view profile', {username: user?.username})
165165

166166
const [staticProfile] = useState(
167167
props.profile && user ? {...props.profile, user: user} : null
168168
)
169169
const {profile: clientProfile, refreshProfile} = useProfileByUser(user)
170-
// Show previous profile while loading another one
170+
// Show the previous profile while loading another one
171171
const profile = clientProfile ?? staticProfile
172172
// console.debug('profile:', user?.username, profile, clientProfile, staticProfile)
173173

174+
if (!isCurrentUser && profile?.disabled) {
175+
return <PageBase
176+
trackPageView={'user page'}
177+
className={'relative p-2 sm:pt-0'}
178+
>
179+
<Col className="items-center justify-center h-full">
180+
<div className="text-xl font-semibold text-center mt-8">
181+
The user disabled their profile.
182+
</div>
183+
</Col>
184+
</PageBase>
185+
}
186+
174187
return (
175188
<PageBase
176189
trackPageView={'user page'}

0 commit comments

Comments
 (0)