upd: announcement
Deskripsi: - tambah - edit - detail No Issues
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
import { ICreateData } from "./type_announcement";
|
||||
import { ICreateData, IFormCreateAnnouncement } from "./type_announcement";
|
||||
|
||||
export const funGetAllAnnouncement = async (path?: string) => {
|
||||
const response = await fetch(`/api/announcement${(path) ? path : ''}`, { next: { tags: ['announcement'] } });
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
}
|
||||
|
||||
export const funGetAnnouncementById = async (path: string) => {
|
||||
const response = await fetch(`/api/announcement/${path}`);
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
export const funCreateAnnouncement = async (data: ICreateData) => {
|
||||
export const funCreateAnnouncement = async (data: IFormCreateAnnouncement) => {
|
||||
if (data.title == "" || data.desc == "")
|
||||
return { success: false, message: 'Silahkan lengkapi form tambah pengumuman' }
|
||||
|
||||
if (data.groups.length == 0)
|
||||
return { success: false, message: 'Silahkan pilih divisi penerima pengumuman' }
|
||||
|
||||
const response = await fetch("/api/announcement", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -19,4 +25,31 @@ export const funCreateAnnouncement = async (data: ICreateData) => {
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
export const funDeleteAnnouncement = async (path: string) => {
|
||||
const response = await fetch(`/api/announcement/${path}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funEditAnnouncement = async (path: string, data: IFormCreateAnnouncement) => {
|
||||
if (data.title == "" || data.desc == "")
|
||||
return { success: false, message: 'Silahkan lengkapi form edit pengumuman' }
|
||||
|
||||
if (data.groups.length == 0)
|
||||
return { success: false, message: 'Silahkan pilih divisi penerima pengumuman' }
|
||||
|
||||
const response = await fetch(`/api/announcement/${path}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
@@ -6,8 +6,8 @@ export interface IListDataAnnouncement {
|
||||
}
|
||||
|
||||
export interface IRootAllAnnouncement {
|
||||
announcement: IAnnouncement
|
||||
allAnnouncementMember: IAllAnnouncementMember[]
|
||||
data: IAnnouncement
|
||||
member: IAllAnnouncementMember
|
||||
}
|
||||
|
||||
export interface IAnnouncement {
|
||||
@@ -17,10 +17,12 @@ export interface IAnnouncement {
|
||||
}
|
||||
|
||||
export interface IAllAnnouncementMember {
|
||||
idAnnouncement: string
|
||||
idGroup: string
|
||||
idDivision: string
|
||||
group: string
|
||||
group: {
|
||||
idGroup: string
|
||||
idDivision: string
|
||||
group: string
|
||||
division: string
|
||||
}[]
|
||||
}
|
||||
|
||||
export interface GroupData {
|
||||
@@ -32,10 +34,26 @@ export interface GroupData {
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface GroupDataEditAnnouncement {
|
||||
id: string;
|
||||
name: string;
|
||||
Division: {
|
||||
idGroup: string;
|
||||
idDivision: string;
|
||||
group: string;
|
||||
division: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface ICreateData {
|
||||
title: string
|
||||
desc: string
|
||||
}
|
||||
|
||||
export interface IFormCreateAnnouncement {
|
||||
title: string
|
||||
desc: string
|
||||
groups: GroupData[]
|
||||
}
|
||||
|
||||
export interface IGroupData {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { hookstate } from "@hookstate/core";
|
||||
import { GroupData } from "./type_announcement";
|
||||
import { GroupData, GroupDataEditAnnouncement } from "./type_announcement";
|
||||
|
||||
|
||||
export const globalMemberAnnouncement = hookstate<GroupData[]>([])
|
||||
export const globalMemberAnnouncement = hookstate<GroupData[]>([])
|
||||
export const globalMemberEditAnnouncement = hookstate<GroupData[]>([])
|
||||
Reference in New Issue
Block a user