mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 11:11:13 -05:00
feat: Implement moderator notifications
This commit is contained in:
@@ -99,11 +99,16 @@ export function DesignerForm({ onSubmit, onCancel, initialData }: DesignerFormPr
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const formData = {
|
||||
...data,
|
||||
founded_year: data.founded_year ? parseInt(String(data.founded_year)) : undefined,
|
||||
};
|
||||
|
||||
if (initialData?.id) {
|
||||
await submitDesignerUpdate(initialData.id, data, user.id);
|
||||
await submitDesignerUpdate(initialData.id, formData, user.id);
|
||||
toast.success('Designer update submitted for review');
|
||||
} else {
|
||||
await submitDesignerCreation(data, user.id);
|
||||
await submitDesignerCreation(formData, user.id);
|
||||
toast.success('Designer submitted for review');
|
||||
}
|
||||
onCancel();
|
||||
|
||||
@@ -101,11 +101,16 @@ export function ManufacturerForm({ onSubmit, onCancel, initialData }: Manufactur
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const formData = {
|
||||
...data,
|
||||
founded_year: data.founded_year ? parseInt(String(data.founded_year)) : undefined,
|
||||
};
|
||||
|
||||
if (initialData?.id) {
|
||||
await submitManufacturerUpdate(initialData.id, data, user.id);
|
||||
await submitManufacturerUpdate(initialData.id, formData, user.id);
|
||||
toast.success('Manufacturer update submitted for review');
|
||||
} else {
|
||||
await submitManufacturerCreation(data, user.id);
|
||||
await submitManufacturerCreation(formData, user.id);
|
||||
toast.success('Manufacturer submitted for review');
|
||||
}
|
||||
onCancel();
|
||||
|
||||
@@ -99,11 +99,16 @@ export function OperatorForm({ onSubmit, onCancel, initialData }: OperatorFormPr
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const formData = {
|
||||
...data,
|
||||
founded_year: data.founded_year ? parseInt(String(data.founded_year)) : undefined,
|
||||
};
|
||||
|
||||
if (initialData?.id) {
|
||||
await submitOperatorUpdate(initialData.id, data, user.id);
|
||||
await submitOperatorUpdate(initialData.id, formData, user.id);
|
||||
toast.success('Operator update submitted for review');
|
||||
} else {
|
||||
await submitOperatorCreation(data, user.id);
|
||||
await submitOperatorCreation(formData, user.id);
|
||||
toast.success('Operator submitted for review');
|
||||
}
|
||||
onCancel();
|
||||
|
||||
@@ -125,13 +125,18 @@ export function PropertyOwnerForm({ onSubmit, onCancel, initialData }: PropertyO
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
if (initialData?.id) {
|
||||
await submitPropertyOwnerUpdate(initialData.id, data, user.id);
|
||||
toast.success('Property owner update submitted for review');
|
||||
} else {
|
||||
await submitPropertyOwnerCreation(data, user.id);
|
||||
toast.success('Property owner submitted for review');
|
||||
}
|
||||
const formData = {
|
||||
...data,
|
||||
founded_year: data.founded_year ? parseInt(String(data.founded_year)) : undefined,
|
||||
};
|
||||
|
||||
if (initialData?.id) {
|
||||
await submitPropertyOwnerUpdate(initialData.id, formData, user.id);
|
||||
toast.success('Property owner update submitted for review');
|
||||
} else {
|
||||
await submitPropertyOwnerCreation(formData, user.id);
|
||||
toast.success('Property owner submitted for review');
|
||||
}
|
||||
onCancel();
|
||||
} catch (error) {
|
||||
console.error('Submission error:', error);
|
||||
|
||||
@@ -327,6 +327,40 @@ class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify all moderators about a new submission
|
||||
*/
|
||||
async notifyModerators(payload: {
|
||||
submission_id: string;
|
||||
submission_type: string;
|
||||
submitter_name: string;
|
||||
action: string;
|
||||
}): Promise<{ success: boolean; count: number; error?: string }> {
|
||||
try {
|
||||
const { data, error } = await supabase.functions.invoke('notify-moderators-submission', {
|
||||
body: payload,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error('Edge function error notifying moderators:', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.log('Moderators notified successfully:', data);
|
||||
return {
|
||||
success: true,
|
||||
count: data?.count || 0
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
console.error('Error notifying moderators:', error);
|
||||
return {
|
||||
success: false,
|
||||
count: 0,
|
||||
error: this.extractErrorMessage(error)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Novu is enabled
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user