Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 015fa9d17a |
@@ -11,6 +11,7 @@ export enum APIPath {
|
||||
FEED = "/feed/:id",
|
||||
JOBADS = "/jobads/:id",
|
||||
SIGNUPS = "/signup/:id",
|
||||
SIGNUPS_DELETE = "/signup/:id/delete",
|
||||
SIGNUPS_EDIT = "/signup/:id/edit",
|
||||
SIGNUP_FORMS = "/signupForm/:id",
|
||||
SIGNUP_FORMS_EMAIL = "/signupForm/:id/sendemail",
|
||||
|
||||
@@ -78,6 +78,15 @@ class SignupApi {
|
||||
}
|
||||
};
|
||||
|
||||
static userDeleteSignup = async (id: number, uuid: string): Promise<void> => {
|
||||
try {
|
||||
await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.SIGNUPS_DELETE, urlParams: { id }, queryParams: { uuid } });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
static getForm = async (id: number, auth = false): Promise<SignupForm> => {
|
||||
try {
|
||||
return await getBackendAPI<SignupForm>({
|
||||
|
||||
@@ -3,7 +3,7 @@ import styled from "styled-components";
|
||||
import colors from "@theme/colors";
|
||||
|
||||
interface ButtonProps {
|
||||
onClick: () => void;
|
||||
onClick: (event?: React.MouseEvent<HTMLButtonElement>) => void;
|
||||
buttonStyle: "hero" | "filled" | "filter" | "bordered";
|
||||
selected?: boolean;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,16 @@ const EditSignUpPage: NextPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const onDelete = async () => {
|
||||
try {
|
||||
await SignupApi.userDeleteSignup(Number(signupId), uuid);
|
||||
toast.success("Sign-up deleted successfully 😎");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Uh oh! Deleting sign-up failed! 😟");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<PageWrapper>
|
||||
<SignUpPageView
|
||||
@@ -74,6 +84,7 @@ const EditSignUpPage: NextPage = () => {
|
||||
formData={formData}
|
||||
onChange={noop}
|
||||
onSubmit={onSubmit}
|
||||
onDelete={onDelete}
|
||||
/>
|
||||
</PageWrapper>
|
||||
);
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
import React from "react";
|
||||
import { NextPage, GetStaticProps } from "next";
|
||||
import Head from "next/head";
|
||||
import useSWR from "swr";
|
||||
import EventsPageView from "@views/EventsPage/EventsPageView";
|
||||
import PageWrapper from "@views/common/PageWrapper";
|
||||
import { fetcher, API, APIPath } from "@api/backend";
|
||||
import Event from "@models/Event";
|
||||
|
||||
const eventApi: API = {
|
||||
path: APIPath.EVENTS,
|
||||
queryParams: {
|
||||
limit: 10,
|
||||
},
|
||||
};
|
||||
|
||||
interface InitialProps {
|
||||
initialEvents: Event[];
|
||||
}
|
||||
|
||||
const EventsPage: NextPage<InitialProps> = ({ initialEvents }) => {
|
||||
const { data: events } = useSWR<Event[]>(eventApi, fetcher, { fallbackData: initialEvents });
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/toiminta/tapahtumat`} />
|
||||
</Head>
|
||||
<PageWrapper>
|
||||
<EventsPageView events={events} />
|
||||
</PageWrapper>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
const initialEvents = fetcher<Event[]>(eventApi);
|
||||
return {
|
||||
props: {
|
||||
initialEvents: await initialEvents,
|
||||
},
|
||||
revalidate: 10,
|
||||
};
|
||||
};
|
||||
|
||||
export default EventsPage;
|
||||
@@ -1,46 +0,0 @@
|
||||
import React from "react";
|
||||
import { NextPage, GetStaticProps } from "next";
|
||||
import Head from "next/head";
|
||||
import useSWR from "swr";
|
||||
import NewsFeedPageView from "@views/NewsFeedPage/NewsFeedPageView";
|
||||
import PageWrapper from "@views/common/PageWrapper";
|
||||
import { fetcher, API, APIPath } from "@api/backend";
|
||||
import Post from "@models/Feed";
|
||||
|
||||
const feedApi: API = {
|
||||
path: APIPath.FEED,
|
||||
queryParams: {
|
||||
limit: 10,
|
||||
},
|
||||
};
|
||||
|
||||
interface InitialProps {
|
||||
initialPosts: Post[];
|
||||
}
|
||||
|
||||
const NewsFeedPage: NextPage<InitialProps> = ({ initialPosts }) => {
|
||||
const { data: posts } = useSWR<Post[]>(feedApi, fetcher, { fallbackData: initialPosts });
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/toiminta/uutiset`} />
|
||||
</Head>
|
||||
<PageWrapper>
|
||||
<NewsFeedPageView posts={posts} />
|
||||
</PageWrapper>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<InitialProps> = async () => {
|
||||
const initialPosts = fetcher<Post[]>(feedApi);
|
||||
return {
|
||||
props: {
|
||||
initialPosts: await initialPosts,
|
||||
},
|
||||
revalidate: 10,
|
||||
};
|
||||
};
|
||||
|
||||
export default NewsFeedPage;
|
||||
@@ -1,63 +0,0 @@
|
||||
import React from "react";
|
||||
|
||||
import {
|
||||
Card,
|
||||
CardSection,
|
||||
} from "@components/index";
|
||||
|
||||
import Event from "@models/Event";
|
||||
import noop from "@utils/noop";
|
||||
import { getTranslateFunc } from "../../i18n";
|
||||
|
||||
interface EventsPageViewProps {
|
||||
events: Event[];
|
||||
}
|
||||
|
||||
const cardTimeOpts: Intl.DateTimeFormatOptions = {
|
||||
day: "numeric",
|
||||
month: "numeric",
|
||||
year: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
};
|
||||
|
||||
const EventsPageView: React.FC<EventsPageViewProps> = ({ events }) => {
|
||||
const isFi = true;
|
||||
const t = getTranslateFunc("fi");
|
||||
|
||||
const buttonText = `${t("Lue lisää")}\xa0›`;
|
||||
|
||||
const locale = isFi ? "fi-FI" : "en-GB";
|
||||
|
||||
const filteredEvents = events.map((e) => ({
|
||||
...e,
|
||||
title: isFi ? e.title_fi : e.title_en,
|
||||
description: isFi ? e.description_fi : e.description_en,
|
||||
content: isFi ? e.content_fi : e.content_en,
|
||||
location: isFi ? e.location_fi : e.location_en,
|
||||
startDate: new Date(e.start_time).toLocaleString(locale, cardTimeOpts),
|
||||
endDate: new Date(e.end_time).toLocaleString(locale, cardTimeOpts),
|
||||
}));
|
||||
return (
|
||||
<CardSection id="#events">
|
||||
{filteredEvents.map((event) => (
|
||||
<Card
|
||||
key={event.id}
|
||||
title={event.title}
|
||||
startTime={new Date(event.start_time).toLocaleString(locale, cardTimeOpts)}
|
||||
text={event.description}
|
||||
link={`/events/${event.id}`}
|
||||
image={{
|
||||
src: event.image || event.tags[0].icon,
|
||||
alt: event.title,
|
||||
}}
|
||||
buttonOnClick={noop}
|
||||
buttonText={buttonText}
|
||||
data-e2e="event-card"
|
||||
/>
|
||||
))}
|
||||
</CardSection>
|
||||
);
|
||||
};
|
||||
|
||||
export default EventsPageView;
|
||||
@@ -1,56 +0,0 @@
|
||||
import React from "react";
|
||||
|
||||
import {
|
||||
Card,
|
||||
CardSection,
|
||||
} from "@components/index";
|
||||
|
||||
import Post from "@models/Feed";
|
||||
import noop from "@utils/noop";
|
||||
import { getTranslateFunc } from "../../i18n";
|
||||
|
||||
interface NewsFeedPageViewProps {
|
||||
posts: Post[];
|
||||
}
|
||||
|
||||
const cardTimeOpts: Intl.DateTimeFormatOptions = {
|
||||
day: "numeric",
|
||||
month: "numeric",
|
||||
year: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
};
|
||||
|
||||
const NewsFeedPageView: React.FC<NewsFeedPageViewProps> = ({ posts }) => {
|
||||
const isFi = true;
|
||||
const t = getTranslateFunc("fi");
|
||||
|
||||
const buttonText = `${t("Lue lisää")}\xa0›`;
|
||||
|
||||
const locale = isFi ? "fi-FI" : "en-GB";
|
||||
|
||||
const filteredFeed = posts.map((post) => ({
|
||||
...post,
|
||||
title: isFi ? post.title_fi : post.title_en,
|
||||
description: isFi ? post.description_fi : post.description_en,
|
||||
content: isFi ? post.content_fi : post.content_en,
|
||||
publish_time: new Date(post.publish_time).toLocaleString(locale, cardTimeOpts),
|
||||
}));
|
||||
return (
|
||||
<CardSection>
|
||||
{filteredFeed.map((post) => (
|
||||
<Card
|
||||
key={post.id}
|
||||
title={post.title}
|
||||
text={post.description}
|
||||
startTime={post.publish_time}
|
||||
link={`/feed/${post.id}`}
|
||||
buttonOnClick={noop}
|
||||
buttonText={buttonText}
|
||||
/>
|
||||
))}
|
||||
</CardSection>
|
||||
);
|
||||
};
|
||||
|
||||
export default NewsFeedPageView;
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
import { SignupForm } from "@models/Signup";
|
||||
import Checkboxes from "@components/Widgets/Checkbox/Checkboxes";
|
||||
import RadioButtonWidget from "@components/Widgets/RadioButton/RadioButtonWidget";
|
||||
import { TextSection, ChangeLanguageButton } from "@components/index";
|
||||
import { TextSection, ChangeLanguageButton, Button } from "@components/index";
|
||||
import colors from "@theme/colors";
|
||||
import FormWrapper from "@views/common/FormWrapper";
|
||||
import Loader from "@components/Loader";
|
||||
@@ -23,6 +23,7 @@ interface SignUpPageViewProps {
|
||||
formData: any;
|
||||
onChange: (e: IChangeEvent<unknown>, es?: ErrorSchema) => unknown;
|
||||
onSubmit: (e: ISubmitEvent<unknown>) => unknown;
|
||||
onDelete: () => void;
|
||||
}
|
||||
|
||||
const StyledSection = styled(TextSection)`
|
||||
@@ -59,6 +60,7 @@ const SignUpPageView: React.FC<SignUpPageViewProps> = ({
|
||||
formData,
|
||||
onChange,
|
||||
onSubmit,
|
||||
onDelete,
|
||||
}) => {
|
||||
const { i18n, t } = useTranslation();
|
||||
const startDate = new Date(signUpForm?.start_time);
|
||||
@@ -127,6 +129,14 @@ const SignUpPageView: React.FC<SignUpPageViewProps> = ({
|
||||
signups = renderList();
|
||||
}
|
||||
|
||||
const deleteButton = (
|
||||
<Button
|
||||
buttonStyle="filled"
|
||||
onClick={onDelete}
|
||||
>Delete
|
||||
</Button>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<LngButton />
|
||||
@@ -137,6 +147,7 @@ const SignUpPageView: React.FC<SignUpPageViewProps> = ({
|
||||
|
||||
<div>
|
||||
{form}
|
||||
{deleteButton}
|
||||
</div>
|
||||
{signups}
|
||||
</StyledSection>
|
||||
|
||||
Reference in New Issue
Block a user