Skip to content

Commit

Permalink
Merge branch 'main' into 77-refactor-env-config
Browse files Browse the repository at this point in the history
  • Loading branch information
expries committed Oct 3, 2024
2 parents dbd1391 + fbca0c6 commit cd5946b
Show file tree
Hide file tree
Showing 56 changed files with 1,836 additions and 944 deletions.
3 changes: 3 additions & 0 deletions app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ VAPID_ADMIN_EMAIL=
NEXT_PUBLIC_APP_INSIGHTS_CONNECTION_STRING=
NEXT_PUBLIC_APP_INSIGHTS_INSTRUMENTATION_KEY=
APP_INSIGHTS_SERVICE_NAME=

# Allowed origin urls used for triggering server actions, separated by comma
ALLOWED_ORIGINS=
30 changes: 30 additions & 0 deletions app/app/contexts/news-feed-highlight-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client';

import { createContext, PropsWithChildren, useContext, useEffect, useState } from 'react';

import { useNewsFeed } from './news-feed-context';

interface HighlightContext {
highlightString?: string;
}

const HighlightContext = createContext<HighlightContext>({});

export function NewsFeedHighlightContextProvider(props: PropsWithChildren) {
const [highlightString, setHighlightString] = useState<string>();
const { filters } = useNewsFeed();

useEffect(
function updateNewsFeedSearchTerm() {
setHighlightString(filters.searchString);
},
[filters.searchString],
);
const ctx: HighlightContext = { highlightString };
return <HighlightContext.Provider value={ctx}>{props.children}</HighlightContext.Provider>;
}

export function useHighlightContext() {
const ctx = useContext(HighlightContext);
return ctx;
}
9 changes: 6 additions & 3 deletions app/app/news/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Box from '@mui/material/Box';
import Container from '@mui/material/Container';
import Stack from '@mui/material/Stack';

import { NewsFeedHighlightContextProvider } from '@/app/contexts/news-feed-highlight-context';
import BreadcrumbsNav from '@/components/common/BreadcrumbsNav';
import ErrorPage from '@/components/error/ErrorPage';
import NewsFeedContainer from '@/components/newsFeed/NewsFeedContainer';
Expand Down Expand Up @@ -50,9 +51,11 @@ async function NewsFeedPage() {
projects={props.projects}
types={props.types}
>
<NewsFeedContainer>
<NewsFeed />
</NewsFeedContainer>
<NewsFeedHighlightContextProvider>
<NewsFeedContainer>
<NewsFeed />
</NewsFeedContainer>
</NewsFeedHighlightContextProvider>
</NewsFeedContextProvider>
</Container>
</Stack>
Expand Down
254 changes: 152 additions & 102 deletions app/components/collaboration/comments/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,42 +85,8 @@ export const addProjectCollaborationComment = withAuth(
);

export const deleteProjectCollaborationComment = withAuth(async (user: UserSession, body: { commentId: string }) => {
const validatedParams = validateParams(deleteCollaborationCommentSchema, body);

if (validatedParams.status !== StatusCodes.OK) {
return {
status: validatedParams.status,
errors: validatedParams.errors,
message: validatedParams.message,
};
}

const comment = await getCollaborationCommentById(dbClient, body.commentId);

if (comment === null) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'No collaboration comment with the specified ID exists',
};
}

if (comment.author !== user.providerId) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'A collaboration comment can only be deleted by its author',
};
}

await deleteCollaborationComment(body.commentId);

return {
status: StatusCodes.OK,
};
});

export const updateProjectCollaborationComment = withAuth(
async (user: UserSession, body: { commentId: string; updatedText: string }) => {
const validatedParams = validateParams(updateCollaborationCommentSchema, body);
try {
const validatedParams = validateParams(deleteCollaborationCommentSchema, body);

if (validatedParams.status !== StatusCodes.OK) {
return {
Expand All @@ -142,22 +108,76 @@ export const updateProjectCollaborationComment = withAuth(
if (comment.author !== user.providerId) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'A collaboration comment can only be edited by its author',
message: 'A collaboration comment can only be deleted by its author',
};
}

const updatedComment = await updateCollaborationComment({
user,
comment: {
id: body.commentId,
comment: body.updatedText,
},
});
await deleteCollaborationComment(body.commentId);

return {
status: StatusCodes.OK,
comment: updatedComment,
};
} catch (err) {
const error: InnoPlatformError = dbError(
`Deleting Collaboration Comment with id: ${body.commentId} by user ${user.providerId}`,
err as Error,
body.commentId,
);
logger.error(error);
throw err;
}
});

export const updateProjectCollaborationComment = withAuth(
async (user: UserSession, body: { commentId: string; updatedText: string }) => {
try {
const validatedParams = validateParams(updateCollaborationCommentSchema, body);

if (validatedParams.status !== StatusCodes.OK) {
return {
status: validatedParams.status,
errors: validatedParams.errors,
message: validatedParams.message,
};
}

const comment = await getCollaborationCommentById(dbClient, body.commentId);

if (comment === null) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'No collaboration comment with the specified ID exists',
};
}

if (comment.author !== user.providerId) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'A collaboration comment can only be edited by its author',
};
}

const updatedComment = await updateCollaborationComment({
user,
comment: {
id: body.commentId,
comment: body.updatedText,
},
});

return {
status: StatusCodes.OK,
comment: updatedComment,
};
} catch (err) {
const error: InnoPlatformError = dbError(
`Updating Collaboration Comment with id: ${body.commentId} by user ${user.providerId}`,
err as Error,
body.commentId,
);
logger.error(error);
throw err;
}
},
);

Expand Down Expand Up @@ -221,87 +241,117 @@ export const addProjectCollaborationCommentResponse = withAuth(

export const deleteProjectCollaborationCommentResponse = withAuth(
async (user: UserSession, body: { responseId: string }) => {
const validatedParams = validateParams(deleteCollaborationCommentResponseSchema, body);
try {
const validatedParams = validateParams(deleteCollaborationCommentResponseSchema, body);

if (validatedParams.status !== StatusCodes.OK) {
return {
status: validatedParams.status,
errors: validatedParams.errors,
message: validatedParams.message,
};
}
if (validatedParams.status !== StatusCodes.OK) {
return {
status: validatedParams.status,
errors: validatedParams.errors,
message: validatedParams.message,
};
}

const response = await getCollaborationCommentResponseById(dbClient, body.responseId);
const response = await getCollaborationCommentResponseById(dbClient, body.responseId);

if (response === null) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'No collaboration comment response with the specified ID exists',
};
}
if (response === null) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'No collaboration comment response with the specified ID exists',
};
}

if (response.author !== user.providerId) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'A collaboration comment response can only be deleted by its author',
};
}

await deleteCollaborationCommentResponse({ user, response: { id: body.responseId } });

if (response.author !== user.providerId) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'A collaboration comment response can only be deleted by its author',
status: StatusCodes.OK,
};
} catch (err) {
const error: InnoPlatformError = dbError(
`Deleting a Collaboration Comment Response with id: ${body.responseId} by user ${user.providerId}`,
err as Error,
body.responseId,
);
logger.error(error);
throw err;
}

await deleteCollaborationCommentResponse({ user, response: { id: body.responseId } });

return {
status: StatusCodes.OK,
};
},
);

export const updateProjectCollaborationCommentResponse = withAuth(
async (user: UserSession, body: { responseId: string; updatedText: string }) => {
const validatedParams = validateParams(updateCollaborationCommentResponseSchema, body);
try {
const validatedParams = validateParams(updateCollaborationCommentResponseSchema, body);

if (validatedParams.status !== StatusCodes.OK) {
return {
status: validatedParams.status,
errors: validatedParams.errors,
message: validatedParams.message,
};
}
if (validatedParams.status !== StatusCodes.OK) {
return {
status: validatedParams.status,
errors: validatedParams.errors,
message: validatedParams.message,
};
}

const response = await getCollaborationCommentResponseById(dbClient, body.responseId);
const response = await getCollaborationCommentResponseById(dbClient, body.responseId);

if (response === null) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'No collaboration comment response with the specified ID exists',
};
}
if (response === null) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'No collaboration comment response with the specified ID exists',
};
}

if (response.author !== user.providerId) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'A collaboration comment response can only be edited by its author',
};
}

const updatedResponse = await updateCollaborationCommentResponseInDb(dbClient, body.responseId, body.updatedText);

if (response.author !== user.providerId) {
return {
status: StatusCodes.BAD_REQUEST,
message: 'A collaboration comment response can only be edited by its author',
status: StatusCodes.OK,
comment: updatedResponse,
};
} catch (err) {
const error: InnoPlatformError = dbError(
`Updating a Collaboration Comment Response with id: ${body.responseId} by user ${user.providerId}`,
err as Error,
body.responseId,
);
logger.error(error);
throw err;
}

const updatedResponse = await updateCollaborationCommentResponseInDb(dbClient, body.responseId, body.updatedText);

return {
status: StatusCodes.OK,
comment: updatedResponse,
};
},
);

export const handleProjectCollaborationCommentResponseUpvotedBy = withAuth(
async (user: UserSession, body: { responseId: string }) => {
const validatedParams = validateParams(collaborationCommentResponseUpvotedBySchema, body);
if (validatedParams.status === StatusCodes.OK) {
await handleCollaborationCommentResponseUpvotedByInDb(dbClient, body.responseId, user.providerId);
return { status: StatusCodes.OK };
try {
const validatedParams = validateParams(collaborationCommentResponseUpvotedBySchema, body);
if (validatedParams.status === StatusCodes.OK) {
await handleCollaborationCommentResponseUpvotedByInDb(dbClient, body.responseId, user.providerId);
return { status: StatusCodes.OK };
}
return {
status: validatedParams.status,
errors: validatedParams.errors,
};
} catch (err) {
const error: InnoPlatformError = dbError(
`Adding an upvote to a Collaboration Comment Response with id: ${body.responseId} by user ${user.providerId}`,
err as Error,
body.responseId,
);
logger.error(error);
throw err;
}
return {
status: validatedParams.status,
errors: validatedParams.errors,
};
},
);
3 changes: 2 additions & 1 deletion app/components/collaboration/survey/SurveyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SurveyQuestion } from '@/common/types';
import { errorMessage } from '@/components/common/CustomToast';
import * as m from '@/src/paraglide/messages.js';
import theme from '@/styles/theme';
import { HighlightText } from '@/utils/highlightText';

import { handleSurveyVote } from './actions';
import { SurveyResponsePicker } from './SurveyResponsePicker';
Expand Down Expand Up @@ -48,7 +49,7 @@ export const SurveyCard = (props: SurveyCardProps) => {
<Grid container item xs={12} md={fill ? 12 : 6} direction="column" sx={leftGridStyles}>
<Grid item>
<Typography variant="h5" color="secondary.contrastText" style={{ fontSize: 20 }} data-testid="text">
{surveyQuestion.question}
<HighlightText text={surveyQuestion.question} />
</Typography>
</Grid>
</Grid>
Expand Down
Loading

0 comments on commit cd5946b

Please sign in to comment.