@@ -35,6 +35,7 @@ import {
3535 deleteUserGithubOAuthToken as dbDeleteUserGithubOAuthToken ,
3636 getTaskByUuid as dbGetTaskByUuid ,
3737 updateProjectDiscordSettings as dbUpdateProjectDiscordSettings ,
38+ deleteProject as dbDeleteProject ,
3839} from '@/lib/db' ;
3940import { z } from 'zod' ;
4041import { auth } from '@/lib/authEdge' ;
@@ -239,7 +240,7 @@ export async function inviteUserToProjectAction(
239240 }
240241 }
241242
242- if ( project . discordWebhookUrl && project . discordNotificationsEnabled ) {
243+ if ( project . discordWebhookUrl && project . discordNotificationsEnabled && project . discordNotifyMembers ) {
243244 await sendDiscordNotification ( project . discordWebhookUrl , {
244245 embeds : [ {
245246 title : "👥 New Member Invited" ,
@@ -375,7 +376,7 @@ export async function createTaskAction(prevState: CreateTaskFormState, formData:
375376 } ;
376377 const createdTask = await dbCreateTask ( taskData ) ;
377378
378- if ( project . discordWebhookUrl && project . discordNotificationsEnabled ) {
379+ if ( project . discordWebhookUrl && project . discordNotificationsEnabled && project . discordNotifyTasks ) {
379380 await sendDiscordNotification ( project . discordWebhookUrl , {
380381 embeds : [ {
381382 title : `✅ New Task Created: ${ createdTask . title } ` ,
@@ -1134,6 +1135,24 @@ export async function createProjectAnnouncementAction(
11341135 content,
11351136 authorUuid : session . user . uuid ,
11361137 } ) ;
1138+ const project = await dbGetProjectByUuid ( projectUuid ) ;
1139+ if ( project ?. discordWebhookUrl && project . discordNotificationsEnabled && project . discordNotifyAnnouncements ) {
1140+ await sendDiscordNotification ( project . discordWebhookUrl , {
1141+ embeds : [ {
1142+ title : `📢 New Announcement: ${ createdAnnouncement . title } ` ,
1143+ description : createdAnnouncement . content . substring ( 0 , 200 ) + ( createdAnnouncement . content . length > 200 ? '...' : '' ) ,
1144+ color : 16729344 , // Orange
1145+ timestamp : new Date ( ) . toISOString ( ) ,
1146+ author : {
1147+ name : createdAnnouncement . authorName || 'FlowUp' ,
1148+ icon_url : createdAnnouncement . authorAvatar
1149+ } ,
1150+ footer : { text : `Project: ${ project . name } ` }
1151+ } ]
1152+ } ) ;
1153+ }
1154+
1155+
11371156 return { message : "Announcement created successfully!" , createdAnnouncement } ;
11381157 } catch ( error : any ) {
11391158 console . error ( "Error creating project announcement:" , error ) ;
@@ -1837,8 +1856,12 @@ const updateDiscordSettingsSchema = z.object({
18371856 projectUuid : z . string ( ) . uuid ( ) ,
18381857 discordWebhookUrl : z . string ( ) . url ( "Please enter a valid Discord webhook URL." ) . or ( z . literal ( '' ) ) ,
18391858 discordNotificationsEnabled : z . enum ( [ 'true' , 'false' ] ) . transform ( v => v === 'true' ) ,
1859+ discordNotifyTasks : z . enum ( [ 'true' , 'false' ] ) . transform ( v => v === 'true' ) . optional ( ) ,
1860+ discordNotifyMembers : z . enum ( [ 'true' , 'false' ] ) . transform ( v => v === 'true' ) . optional ( ) ,
1861+ discordNotifyAnnouncements : z . enum ( [ 'true' , 'false' ] ) . transform ( v => v === 'true' ) . optional ( ) ,
18401862} ) ;
18411863
1864+
18421865export async function updateProjectDiscordSettingsAction (
18431866 prevState : UpdateProjectDiscordSettingsFormState ,
18441867 formData : FormData
@@ -1852,21 +1875,24 @@ export async function updateProjectDiscordSettingsAction(
18521875 projectUuid : formData . get ( 'projectUuid' ) ,
18531876 discordWebhookUrl : formData . get ( 'discordWebhookUrl' ) ,
18541877 discordNotificationsEnabled : formData . get ( 'discordNotificationsEnabled' ) ,
1878+ discordNotifyTasks : formData . get ( 'discordNotifyTasks' ) ,
1879+ discordNotifyMembers : formData . get ( 'discordNotifyMembers' ) ,
1880+ discordNotifyAnnouncements : formData . get ( 'discordNotifyAnnouncements' ) ,
18551881 } ) ;
18561882
18571883 if ( ! validatedFields . success ) {
18581884 return { error : "Invalid input: " + validatedFields . error . flatten ( ) . fieldErrors . discordWebhookUrl ?. join ( ', ' ) } ;
18591885 }
18601886
1861- const { projectUuid, discordWebhookUrl, discordNotificationsEnabled } = validatedFields . data ;
1862-
1887+ const { projectUuid, discordWebhookUrl, discordNotificationsEnabled, discordNotifyTasks , discordNotifyMembers , discordNotifyAnnouncements } = validatedFields . data ;
1888+
18631889 try {
18641890 const userRole = await dbGetProjectMemberRole ( projectUuid , session . user . uuid ) ;
18651891 if ( ! userRole || ! [ 'owner' , 'co-owner' ] . includes ( userRole ) ) {
18661892 return { error : "You do not have permission to change Discord settings for this project." } ;
18671893 }
18681894
1869- const updatedProject = await dbUpdateProjectDiscordSettings ( projectUuid , discordWebhookUrl , discordNotificationsEnabled ) ;
1895+ const updatedProject = await dbUpdateProjectDiscordSettings ( projectUuid , discordWebhookUrl , discordNotificationsEnabled , discordNotifyTasks , discordNotifyMembers , discordNotifyAnnouncements ) ;
18701896
18711897 if ( ! updatedProject ) {
18721898 return { error : "Failed to update project settings in the database." } ;
@@ -1878,3 +1904,40 @@ export async function updateProjectDiscordSettingsAction(
18781904 return { error : error . message || "An unexpected error occurred." } ;
18791905 }
18801906}
1907+
1908+ export interface DeleteProjectFormState {
1909+ success ?: boolean ;
1910+ message ?: string ;
1911+ error ?: string ;
1912+ }
1913+
1914+ export async function deleteProjectAction (
1915+ prevState : DeleteProjectFormState ,
1916+ formData : FormData
1917+ ) : Promise < DeleteProjectFormState > {
1918+ const session = await auth ( ) ;
1919+ if ( ! session ?. user ?. uuid ) {
1920+ return { error : "Authentication required." } ;
1921+ }
1922+
1923+ const projectUuid = formData . get ( 'projectUuid' ) as string ;
1924+ if ( ! projectUuid ) {
1925+ return { error : "Project UUID is required." } ;
1926+ }
1927+
1928+ try {
1929+ const userRole = await dbGetProjectMemberRole ( projectUuid , session . user . uuid ) ;
1930+ if ( userRole !== 'owner' ) {
1931+ return { error : "Only the project owner can delete this project." } ;
1932+ }
1933+
1934+ const success = await dbDeleteProject ( projectUuid ) ;
1935+ if ( success ) {
1936+ return { success : true , message : "Project deleted successfully." } ;
1937+ }
1938+ return { error : "Failed to delete project from the database." } ;
1939+ } catch ( error : any ) {
1940+ console . error ( `Error deleting project ${ projectUuid } :` , error ) ;
1941+ return { error : error . message || "An unexpected error occurred." } ;
1942+ }
1943+ }
0 commit comments