Skip to content

Commit d9cac5a

Browse files
committed
#3873 isOnGuestHomePage boolean added to link types
1 parent 2159a19 commit d9cac5a

10 files changed

Lines changed: 72 additions & 24 deletions

File tree

src/backend/src/controllers/projects.controllers.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,16 @@ export default class ProjectsController {
166166

167167
static async createLinkType(req: Request, res: Response, next: NextFunction) {
168168
try {
169-
const { name, iconName, required } = req.body;
169+
const { name, iconName, required, isOnGuestHomePage } = req.body;
170170

171-
const newLinkType = await ProjectsService.createLinkType(req.currentUser, name, iconName, required, req.organization);
171+
const newLinkType = await ProjectsService.createLinkType(
172+
req.currentUser,
173+
name,
174+
iconName,
175+
required,
176+
req.organization,
177+
isOnGuestHomePage
178+
);
172179
res.status(200).json(newLinkType);
173180
} catch (error: unknown) {
174181
next(error);
@@ -453,13 +460,14 @@ export default class ProjectsController {
453460
static async editLinkType(req: Request, res: Response, next: NextFunction) {
454461
try {
455462
const { linkTypeName } = req.params as Record<string, string>;
456-
const { name: newName, iconName, required } = req.body;
463+
const { name: newName, iconName, required, isOnGuestHomePage } = req.body;
457464
const linkTypeUpdated = await ProjectsService.editLinkType(
458465
linkTypeName,
459466
iconName,
460467
required,
461468
req.currentUser,
462469
req.organization,
470+
isOnGuestHomePage,
463471
newName
464472
);
465473
res.status(200).json(linkTypeUpdated);

src/backend/src/prisma/migrations/20260221213604_guest_home_page/migration.sql renamed to src/backend/src/prisma/migrations/20260305012944_guest_home_page/migration.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@
55
- You are about to drop the column `exploreAsGuestImageId` on the `Organization` table. All the data in the column will be lost.
66
77
*/
8+
-- DropForeignKey
9+
ALTER TABLE "Sponsor" DROP CONSTRAINT "Sponsor_sponsorTierId_fkey";
10+
11+
-- AlterTable
12+
ALTER TABLE "Link_Type" ADD COLUMN "isOnGuestHomePage" BOOLEAN NOT NULL DEFAULT false;
13+
814
-- AlterTable
915
ALTER TABLE "Organization" DROP COLUMN "applyInterestImageId",
1016
DROP COLUMN "exploreAsGuestImageId",
1117
ADD COLUMN "platformDescription" TEXT NOT NULL DEFAULT '',
1218
ADD COLUMN "platformLogoImageId" TEXT;
19+
20+
-- AlterTable
21+
ALTER TABLE "Sponsor" ALTER COLUMN "valueTypes" DROP DEFAULT;
22+
23+
-- AddForeignKey
24+
ALTER TABLE "Sponsor" ADD CONSTRAINT "Sponsor_sponsorTierId_fkey" FOREIGN KEY ("sponsorTierId") REFERENCES "Sponsor_Tier"("sponsorTierId") ON DELETE SET NULL ON UPDATE CASCADE;

src/backend/src/prisma/schema.prisma

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,17 @@ model Work_Package {
583583
}
584584

585585
model Link_Type {
586-
id String @id @default(uuid())
587-
name String
588-
dateCreated DateTime @default(now())
589-
iconName String
590-
required Boolean
591-
creatorId String
592-
creator User @relation(name: "linkTypeCreator", fields: [creatorId], references: [userId])
593-
links Link[] @relation(name: "linkTypes")
594-
organizationId String
595-
organization Organization @relation(fields: [organizationId], references: [organizationId])
586+
id String @id @default(uuid())
587+
name String
588+
dateCreated DateTime @default(now())
589+
iconName String
590+
required Boolean
591+
creatorId String
592+
creator User @relation(name: "linkTypeCreator", fields: [creatorId], references: [userId])
593+
links Link[] @relation(name: "linkTypes")
594+
organizationId String
595+
organization Organization @relation(fields: [organizationId], references: [organizationId])
596+
isOnGuestHomePage Boolean @default(false)
596597
597598
@@unique([name, organizationId], name: "uniqueLinkType")
598599
@@index([organizationId])

src/backend/src/services/projects.services.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ export default class ProjectsService {
584584
name: string,
585585
iconName: string,
586586
required: boolean,
587-
organization: Organization
587+
organization: Organization,
588+
isOnGuestHomePage: boolean
588589
): Promise<LinkType> {
589590
if (!(await userHasPermission(user.userId, organization.organizationId, isAdmin)))
590591
throw new AccessDeniedException('Only admins can create link types');
@@ -601,7 +602,8 @@ export default class ProjectsService {
601602
creatorId: user.userId,
602603
iconName,
603604
required,
604-
organizationId: organization.organizationId
605+
organizationId: organization.organizationId,
606+
isOnGuestHomePage
605607
}
606608
});
607609

@@ -623,6 +625,7 @@ export default class ProjectsService {
623625
required: boolean,
624626
submitter: User,
625627
organization: Organization,
628+
isOnGuestHomePage: boolean,
626629
newName?: string
627630
): Promise<LinkType> {
628631
if (!(await userHasPermission(submitter.userId, organization.organizationId, isAdmin)))
@@ -660,7 +663,8 @@ export default class ProjectsService {
660663
data: {
661664
name: newName && newName ? newName : linkName,
662665
iconName,
663-
required
666+
required,
667+
isOnGuestHomePage
664668
}
665669
});
666670
return linkTypeUpdated;

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/LinkTypes/LinkTypeFormModal.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const LinkTypeFormModal = ({ open, handleClose, defaultValues, onSubmit, linkTyp
3131
.required('LinkType Name is Required')
3232
.test('unique-LinkType-test', 'LinkType name must be unique', uniqueLinkTypeTest),
3333
iconName: yup.string().required('Icon name is required'),
34-
required: yup.boolean().required('Required field must be specified')
34+
required: yup.boolean().required('Required field must be specified'),
35+
isOnGuestHomePage: yup.boolean().required('Guest page field must be specified')
3536
});
3637

3738
const theme = useTheme();
@@ -47,7 +48,8 @@ const LinkTypeFormModal = ({ open, handleClose, defaultValues, onSubmit, linkTyp
4748
defaultValues: {
4849
name: defaultValues?.name ?? '',
4950
iconName: defaultValues?.iconName ?? '',
50-
required: defaultValues?.required ?? false
51+
required: defaultValues?.required ?? false,
52+
isOnGuestHomePage: defaultValues?.required ?? false
5153
}
5254
});
5355

@@ -99,6 +101,19 @@ const LinkTypeFormModal = ({ open, handleClose, defaultValues, onSubmit, linkTyp
99101
<FormHelperText error>{errors.required?.message}</FormHelperText>
100102
</FormControl>
101103
</Grid>
104+
<Grid item xs={6}>
105+
<FormControl fullWidth>
106+
<FormLabel sx={{ '&.Mui-focused': { color: theme.palette.text.secondary } }}>
107+
Appears on Guest Home Page
108+
</FormLabel>
109+
<Controller
110+
name="isOnGuestHomePage"
111+
control={control}
112+
render={({ field }) => <Switch {...field} checked={field.value} />}
113+
/>
114+
<FormHelperText error>{errors.required?.message}</FormHelperText>
115+
</FormControl>
116+
</Grid>
102117
<Grid item xs={6}>
103118
<FormControl fullWidth>
104119
<Box style={{ display: 'flex', verticalAlign: 'middle', alignItems: 'center' }}>

src/frontend/src/pages/HomePage/IntroGuestHomePage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const IntroGuestHomePage = () => {
6262
)
6363
return <LoadingIndicator />;
6464

65+
const guestPageLinks = usefulLinks?.filter((link) => link.linkType.isOnGuestHomePage);
66+
6567
return (
6668
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center', px: 2 }}>
6769
<Typography mt={2} variant="h4" sx={{ fontWeight: 'bold' }}>
@@ -101,7 +103,7 @@ const IntroGuestHomePage = () => {
101103
</Typography>
102104
<Box sx={{ mt: 2, width: '100%', display: 'flex', justifyContent: 'center' }}>
103105
<Stack direction="row" flexWrap="wrap" gap={2} useFlexGap justifyContent="center">
104-
{usefulLinks.map((link) => (
106+
{guestPageLinks.map((link) => (
105107
<Link
106108
key={link.linkId}
107109
href={link.url}

src/frontend/src/pages/HomePage/components/FeaturedProjects.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { wbsPipe } from 'shared';
1010
import LoadingIndicator from '../../../components/LoadingIndicator';
1111
import ScrollablePageBlock from './ScrollablePageBlock';
1212
import EmptyPageBlockDisplay from './EmptyPageBlockDisplay';
13-
import { Box, Stack, useMediaQuery } from '@mui/material';
13+
import { Box, Stack, useMediaQuery, useTheme } from '@mui/material';
1414
import { Error } from '@mui/icons-material';
1515

1616
const NoFeaturedProjectsDisplay: React.FC = () => {

src/frontend/src/pages/HomePage/components/GuestOrganizationInfo.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const GuestOrganizationInfo = () => {
3030
const theme = useTheme();
3131
const { data: organization, isLoading, isError, error } = useCurrentOrganization();
3232
const {
33-
data: usefulLinks,
33+
data: links,
3434
isLoading: usefulLinksIsLoading,
3535
isError: usefulLinksIsError,
3636
error: usefulLinksError
@@ -40,9 +40,11 @@ const GuestOrganizationInfo = () => {
4040
if (isLoading || !organization) return <LoadingIndicator />;
4141
if (isError) return <ErrorPage message={error?.message} />;
4242

43-
if (!usefulLinks || usefulLinksIsLoading || !linkTypes || linkTypesIsLoading) return <LoadingIndicator />;
43+
if (!links || usefulLinksIsLoading || !linkTypes || linkTypesIsLoading) return <LoadingIndicator />;
4444
if (usefulLinksIsError) return <ErrorPage message={usefulLinksError.message} />;
4545

46+
const usefulLinks = links?.filter((link) => !link.linkType.isOnGuestHomePage);
47+
4648
return (
4749
<Card
4850
sx={{

src/frontend/src/pages/HomePage/components/OnboardingInfoSection.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ const OnboardingInfoSection: React.FC = () => {
1515
error: organizationError
1616
} = useCurrentOrganization();
1717

18-
const { data: links, isError: linksIsError, error: linksError, isLoading: linksIsLoading } = useAllUsefulLinks();
18+
const { data: usefulLinks, isError: linksIsError, error: linksError, isLoading: linksIsLoading } = useAllUsefulLinks();
1919

2020
if (organizationIsError) {
2121
return <ErrorPage message={organizationError.message} />;
2222
}
2323

2424
if (linksIsError) return <ErrorPage message={linksError?.message} />;
2525

26-
if (!organization || organizationIsLoading || !links || linksIsLoading) return <LoadingIndicator />;
26+
if (!organization || organizationIsLoading || !usefulLinks || linksIsLoading) return <LoadingIndicator />;
27+
28+
const links = usefulLinks?.filter((link) => !link.linkType.isOnGuestHomePage);
2729

2830
return (
2931
<Grid container item sx={{ display: 'flex', flexDirection: 'column', gap: 2.5 }}>

src/shared/src/types/project-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export interface LinkType {
132132
name: string;
133133
required: boolean;
134134
iconName: string;
135+
isOnGuestHomePage: boolean;
135136
}
136137

137138
export interface Link {
@@ -186,6 +187,7 @@ export interface LinkTypeCreatePayload {
186187
name: string;
187188
iconName: string;
188189
required: boolean;
190+
isOnGuestHomePage: boolean;
189191
}
190192

191193
export interface DescriptionBulletTypeCreatePayload {

0 commit comments

Comments
 (0)