Преглед изворни кода

Update for the user function

master
B.E.N.S.O.N пре 12 часа
родитељ
комит
b7dfb980b2
3 измењених фајлова са 11 додато и 5 уклоњено
  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 Прегледај датотеку

@@ -66,7 +66,7 @@ export const editUser = async (id: number, 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",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
@@ -76,7 +76,7 @@ export const createUser = async (data: UserInputs) => {
};

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",
headers: { "Content-Type": "application/json" },
});


+ 6
- 2
src/app/utils/fetchUtil.ts Прегледај датотеку

@@ -41,8 +41,12 @@ export async function serverFetchWithNoContent(...args: FetchParams) {
case 401:
signOutUser();
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 Прегледај датотеку

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

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


Loading…
Откажи
Сачувај