Przeglądaj źródła

Update for the user function

master
B.E.N.S.O.N 12 godzin temu
rodzic
commit
b7dfb980b2
3 zmienionych plików z 11 dodań i 5 usunięć
  1. +2
    -2
      src/app/api/user/actions.ts
  2. +6
    -2
      src/app/utils/fetchUtil.ts
  3. +3
    -1
      src/components/UserSearch/UserSearch.tsx

+ 2
- 2
src/app/api/user/actions.ts Wyświetl plik

@@ -66,7 +66,7 @@ export const editUser = async (id: number, data: UserInputs) => {
}; };


export const createUser = async (data: UserInputs) => { export const createUser = async (data: UserInputs) => {
const newUser = serverFetchWithNoContent(`${BASE_API_URL}/user/save`, {
const newUser = await serverFetchWithNoContent(`${BASE_API_URL}/user/save`, {
method: "POST", method: "POST",
body: JSON.stringify(data), body: JSON.stringify(data),
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
@@ -76,7 +76,7 @@ export const createUser = async (data: UserInputs) => {
}; };


export const deleteUser = async (id: number) => { export const deleteUser = async (id: number) => {
const newUser = serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, {
const newUser = await serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, {
method: "DELETE", method: "DELETE",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
}); });


+ 6
- 2
src/app/utils/fetchUtil.ts Wyświetl plik

@@ -41,8 +41,12 @@ export async function serverFetchWithNoContent(...args: FetchParams) {
case 401: case 401:
signOutUser(); signOutUser();
default: default:
console.error(await response.text());
throw Error("Something went wrong fetching data in server.");
const errorText = await response.text();
console.error(`Server error (${response.status}):`, errorText);
throw new ServerFetchError(
`Server error: ${response.status} ${response.statusText}. ${errorText || "Something went wrong fetching data in server."}`,
response
);
} }
} }
} }


+ 3
- 1
src/components/UserSearch/UserSearch.tsx Wyświetl plik

@@ -61,9 +61,11 @@ const UserSearch: React.FC<Props> = ({ users }) => {
const onDeleteClick = useCallback((users: UserResult) => { const onDeleteClick = useCallback((users: UserResult) => {
deleteDialog(async () => { deleteDialog(async () => {
await deleteUser(users.id); await deleteUser(users.id);
setFilteredUser(prev => prev.filter(user => user.id !== users.id));
router.refresh();
successDialog(t("Delete Success"), t); successDialog(t("Delete Success"), t);
}, t); }, t);
}, [t]);
}, [t, router]);


const columns = useMemo<Column<UserResult>[]>( const columns = useMemo<Column<UserResult>[]>(
() => [ () => [


Ładowanie…
Anuluj
Zapisz