Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/cb-service-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- main
schedule:
- cron: "0 11 * * 0"
permissions:
contents: read
jobs:
tests:
runs-on: ubuntu-latest
Expand Down
25 changes: 11 additions & 14 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { validateEmail } from '../util/helpers/validateEmail';
import Image from 'next/image';
import Notification from '../components/Notification';

export default function Home({ origin }) {
export default function Home() {
const [selectedProfile, setSelectedProfile] = useState(undefined);
const [userProfiles, setUserProfiles] = useState([]);
const [isProfilesLoading, setIsProfilesLoading] = useState(true);
Expand Down Expand Up @@ -38,8 +38,10 @@ export default function Home({ origin }) {
useEffect(() => {
const fetchAllProfiles = () => {
fetch(
`${origin}/api/user${
searchString ? `?search=${searchString}&limit=200` : '?limit=200'
`/api/user${
searchString
? `?search=${encodeURIComponent(searchString)}&limit=200`
: '?limit=200'
}`,
{
method: 'GET',
Expand Down Expand Up @@ -79,7 +81,7 @@ export default function Home({ origin }) {
});
};
fetchAllProfiles();
}, [searchString, origin]);
}, [searchString]);

const openCreateModal = () => {
setIsCreateModalOpen(true);
Expand All @@ -94,7 +96,7 @@ export default function Home({ origin }) {
setLastName(undefined);
setEmail(undefined);

fetch(`${origin}/api/user`, {
fetch(`/api/user`, {
method: 'POST',
body: JSON.stringify({
firstName: firstName,
Expand Down Expand Up @@ -137,7 +139,7 @@ export default function Home({ origin }) {
* @return {Promise<void>}
*/
const handleProfileDeletion = (pid) => {
fetch(`${origin}/api/user?pid=${pid}`, { method: 'DELETE' })
fetch(`/api/user?pid=${encodeURIComponent(pid)}`, { method: 'DELETE' })
.then((response) => {
if (response.status === 401) {
setIsReadonlyNotificationOpen(true);
Expand Down Expand Up @@ -168,7 +170,7 @@ export default function Home({ origin }) {
* @param pid
*/
const handleProfileEdit = (pid) => {
fetch(`${origin}/api/user?pid=${pid}`, {
fetch(`/api/user?pid=${encodeURIComponent(pid)}`, {
method: 'PUT',
body: JSON.stringify({
firstName: updatedFirstName && updatedFirstName,
Expand Down Expand Up @@ -314,12 +316,7 @@ export default function Home({ origin }) {
);
}

export async function getServerSideProps(context) {
const { req } = context;

const protocol = req.headers['x-forwarded-proto'] || 'http';
const origin = req ? `${protocol}://${req.headers.host}` : '';

export async function getServerSideProps() {
let connection = await connectToDatabase();

const { profileCollection } = connection;
Expand All @@ -338,6 +335,6 @@ export async function getServerSideProps(context) {
}

return {
props: { isConnected, origin },
props: { isConnected },
};
}
Loading