fix code style, use names from api instead of hardcoding for flatmates users
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
import { create } from "zustand";
|
||||
import { devtools } from "zustand/middleware";
|
||||
import Flatastic from "@/api/flatastic";
|
||||
import type { FlatasticChore } from "@/types/flatasticChore";
|
||||
import type { FlatasticChore, FlatasticUser } from "@/types/flatasticChore";
|
||||
|
||||
// biome-ignore format: deep
|
||||
function parseInformationData(data): FlatasticUser[] {
|
||||
return data.flatmates.map((user: { id: string; firstName: string }) => ({
|
||||
id: user.id as string,
|
||||
firstName: user.firstName as string,
|
||||
}));
|
||||
}
|
||||
|
||||
const useFlatasticStore = create(
|
||||
devtools(
|
||||
(set) => ({
|
||||
chores: [],
|
||||
flatasticData: {
|
||||
chores: [] as FlatasticChore[],
|
||||
users: [] as FlatasticUser[],
|
||||
},
|
||||
fetch: async () => {
|
||||
if (!import.meta.env.VITE_FLATTASTIC_API_KEY) {
|
||||
throw new Error("Flatastic API Key is not set");
|
||||
@@ -15,9 +26,16 @@ const useFlatasticStore = create(
|
||||
import.meta.env.VITE_FLATTASTIC_API_KEY,
|
||||
);
|
||||
const data = await flatastic.getTaskList();
|
||||
const dataB = await flatastic.getInformation();
|
||||
|
||||
console.log("Flatastic chores fetched:", data);
|
||||
set({ chores: data as FlatasticChore[] });
|
||||
console.log("Flatastic information fetched:", dataB);
|
||||
set({
|
||||
flatasticData: {
|
||||
chores: data as FlatasticChore[],
|
||||
users: parseInformationData(dataB),
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user