-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
16,899 additions
and
6,289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
22.6.0 | ||
22.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import ts from "typescript-eslint"; | ||
import server from "@tietokilta/eslint-config/server"; | ||
|
||
export default ts.config(...server, { | ||
rules: { | ||
"unicorn/prefer-node-protocol": "off", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { CollectionConfig, FieldHook } from "payload/types"; | ||
import type { AwardedHonor } from "@tietokilta/cms-types/payload"; | ||
import { signedIn } from "../../access/signed-in"; | ||
import { guildYearField } from "../../fields/guild-year"; | ||
|
||
const formatDisplayTitle: FieldHook<AwardedHonor> = ({ | ||
data: awardedHonor, | ||
}) => { | ||
if (!awardedHonor?.name) { | ||
return "Untitled member"; | ||
} | ||
|
||
if (!awardedHonor.guildYear) { | ||
return awardedHonor.name; | ||
} | ||
|
||
return `${awardedHonor.name}, ${awardedHonor.guildYear}`; | ||
}; | ||
|
||
export const AwardedHonors = { | ||
slug: "awarded-honors", | ||
defaultSort: "-guildYear", | ||
admin: { | ||
useAsTitle: "displayTitle", | ||
defaultColumns: ["description", "guildYear"], | ||
}, | ||
access: { | ||
read: () => true, | ||
create: signedIn, | ||
update: signedIn, | ||
delete: signedIn, | ||
}, | ||
fields: [ | ||
{ | ||
name: "displayTitle", | ||
type: "text", | ||
admin: { | ||
hidden: true, | ||
}, | ||
hooks: { | ||
beforeChange: [formatDisplayTitle], | ||
}, | ||
}, | ||
guildYearField({ | ||
name: "guildYear", | ||
required: true, | ||
}), | ||
{ | ||
name: "name", | ||
type: "text", | ||
required: true, | ||
}, | ||
{ | ||
name: "description", | ||
type: "textarea", | ||
required: false, | ||
localized: true, | ||
}, | ||
], | ||
} as const satisfies CollectionConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { CollectionConfig } from "payload/types"; | ||
import { signedIn } from "../../access/signed-in"; | ||
|
||
export const Honors = { | ||
slug: "honors", | ||
defaultSort: "-name", | ||
admin: { | ||
useAsTitle: "name", | ||
defaultColumns: ["name", "awardedHonors"], | ||
}, | ||
access: { | ||
read: () => true, | ||
create: signedIn, | ||
update: signedIn, | ||
delete: signedIn, | ||
}, | ||
fields: [ | ||
{ | ||
name: "name", | ||
type: "text", | ||
required: true, | ||
localized: true, | ||
}, | ||
{ | ||
name: "awardedHonors", | ||
type: "array", | ||
required: true, | ||
minRows: 1, | ||
fields: [ | ||
{ | ||
name: "awardedHonor", | ||
type: "relationship", | ||
relationTo: "awarded-honors", | ||
}, | ||
], | ||
}, | ||
], | ||
} as const satisfies CollectionConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
apps/cms/src/collections/weekly-newsletters/newsletter-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { Button } from "@tietokilta/ui"; | ||
import * as React from "react"; | ||
|
||
const getIdFromUrl = (): string => { | ||
const pathArray = window.location.pathname.split("/"); | ||
const id = pathArray[pathArray.length - 1]; | ||
return id; | ||
}; | ||
|
||
const getTelegramMessage = async ( | ||
locale: string, | ||
): Promise<{ | ||
message: string; | ||
}> => { | ||
const newsletterId = getIdFromUrl(); | ||
const response = await fetch( | ||
`/api/weekly-newsletters/telegram/${newsletterId}?locale=${locale}`, | ||
); | ||
return (await response.json()) as { message: string }; | ||
}; | ||
|
||
const copyTelegramMessage = async (locale: string): Promise<void> => { | ||
const textToCopy = await getTelegramMessage(locale); | ||
void navigator.clipboard.writeText(textToCopy.message); | ||
}; | ||
|
||
const NewsletterButton = (): React.ReactElement => { | ||
const handleButtonClick = async (): Promise<void> => { | ||
// eslint-disable-next-line no-alert -- Good to have confirmation | ||
const confirmed = confirm( | ||
`Are you sure you want to send email? Remember to publish changes before.`, | ||
); | ||
if (!confirmed) return; | ||
await fetch(`/api/weekly-newsletters/mail/${newsletterId}`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
}; | ||
const buttonStyle = { | ||
padding: "10px 20px", | ||
fontSize: "16px", | ||
borderRadius: "5px", | ||
backgroundColor: "#000", | ||
color: "white", | ||
border: "none", | ||
cursor: "pointer", | ||
transition: "background-color 0.3s ease", | ||
}; | ||
const buttonHoverStyle = { | ||
backgroundColor: "#333333", | ||
}; | ||
const newsletterId = getIdFromUrl(); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
display: "grid", | ||
gridTemplateColumns: "repeat(2, 1fr)", | ||
gridGap: "10px", | ||
maxWidth: "400px", | ||
margin: "0 auto", | ||
}} | ||
> | ||
<Button | ||
style={buttonStyle} | ||
onMouseOver={(e) => | ||
((e.target as HTMLElement).style.backgroundColor = | ||
buttonHoverStyle.backgroundColor) | ||
} | ||
onMouseOut={(e) => | ||
((e.target as HTMLElement).style.backgroundColor = | ||
buttonStyle.backgroundColor) | ||
} | ||
onClick={() => void handleButtonClick()} | ||
> | ||
Send email | ||
</Button> | ||
<a | ||
href={`/api/weekly-newsletters/mail/${newsletterId}`} | ||
style={buttonStyle} | ||
onMouseOver={(e) => | ||
((e.target as HTMLElement).style.backgroundColor = | ||
buttonHoverStyle.backgroundColor) | ||
} | ||
onMouseOut={(e) => | ||
((e.target as HTMLElement).style.backgroundColor = | ||
buttonStyle.backgroundColor) | ||
} | ||
> | ||
Download HTML | ||
</a> | ||
<Button | ||
style={buttonStyle} | ||
onMouseOver={(e) => | ||
((e.target as HTMLElement).style.backgroundColor = | ||
buttonHoverStyle.backgroundColor) | ||
} | ||
onMouseOut={(e) => | ||
((e.target as HTMLElement).style.backgroundColor = | ||
buttonStyle.backgroundColor) | ||
} | ||
onClick={() => void copyTelegramMessage("fi")} | ||
> | ||
Copy finnish tg | ||
</Button> | ||
<Button | ||
style={buttonStyle} | ||
onMouseOver={(e) => | ||
((e.target as HTMLElement).style.backgroundColor = | ||
buttonHoverStyle.backgroundColor) | ||
} | ||
onMouseOut={(e) => | ||
((e.target as HTMLElement).style.backgroundColor = | ||
buttonStyle.backgroundColor) | ||
} | ||
onClick={() => void copyTelegramMessage("en")} | ||
> | ||
Copy english tg | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NewsletterButton; |
Oops, something went wrong.