feat: notifications, redux, tailwind
This commit is contained in:
23
src/lib/features/auth/authSlice.ts
Normal file
23
src/lib/features/auth/authSlice.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface AuthState {
|
||||
phoneNumber: string | null;
|
||||
}
|
||||
|
||||
const initialState: AuthState = {
|
||||
phoneNumber: null,
|
||||
};
|
||||
|
||||
export const authSlice = createSlice({
|
||||
name: "authentication",
|
||||
initialState,
|
||||
reducers: {
|
||||
setPhoneNumber: (state, action: PayloadAction<string | null>) => {
|
||||
state.phoneNumber = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setPhoneNumber } = authSlice.actions;
|
||||
|
||||
export default authSlice.reducer;
|
||||
8
src/lib/features/rootReducer.ts
Normal file
8
src/lib/features/rootReducer.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { combineReducers } from "@reduxjs/toolkit";
|
||||
import authReducer from "@/lib/features/auth/authSlice";
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
auth: authReducer,
|
||||
});
|
||||
|
||||
export default rootReducer;
|
||||
1
src/lib/notifications/index.ts
Normal file
1
src/lib/notifications/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from "./notifications";
|
||||
46
src/lib/notifications/notifications.ts
Normal file
46
src/lib/notifications/notifications.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { notifications } from "@mantine/notifications";
|
||||
|
||||
type CustomNotifications = {
|
||||
notify: (...params: Parameters<typeof notifications.show>) => void;
|
||||
success: (...params: Parameters<typeof notifications.show>) => void;
|
||||
warn: (...params: Parameters<typeof notifications.show>) => void;
|
||||
error: (...params: Parameters<typeof notifications.show>) => void;
|
||||
guess: (
|
||||
ok: boolean,
|
||||
...params: Parameters<typeof notifications.show>
|
||||
) => void;
|
||||
} & typeof notifications;
|
||||
|
||||
const customNotifications: CustomNotifications = {
|
||||
...notifications,
|
||||
notify: params => {
|
||||
return notifications.show({
|
||||
...params,
|
||||
color: "blue",
|
||||
});
|
||||
},
|
||||
success: params => {
|
||||
return notifications.show({
|
||||
...params,
|
||||
color: "green",
|
||||
});
|
||||
},
|
||||
warn: params => {
|
||||
return notifications.show({
|
||||
...params,
|
||||
color: "yellow",
|
||||
});
|
||||
},
|
||||
error: params => {
|
||||
return notifications.show({
|
||||
...params,
|
||||
color: "red",
|
||||
});
|
||||
},
|
||||
guess: (ok: boolean, params) => {
|
||||
if (ok) return customNotifications.success(params);
|
||||
return customNotifications.error(params);
|
||||
},
|
||||
};
|
||||
|
||||
export { customNotifications as notifications };
|
||||
28
src/lib/store.ts
Normal file
28
src/lib/store.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { persistReducer, persistStore } from "redux-persist";
|
||||
import storage from "redux-persist/lib/storage";
|
||||
import rootReducer from "@/lib/features/rootReducer";
|
||||
|
||||
const persistConfig = {
|
||||
key: "root",
|
||||
storage,
|
||||
whitelist: ["targetService", "verification", "auth"],
|
||||
};
|
||||
|
||||
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: persistedReducer,
|
||||
middleware: getDefaultMiddleware =>
|
||||
getDefaultMiddleware({
|
||||
serializableCheck: false,
|
||||
}),
|
||||
});
|
||||
|
||||
export const persistor = persistStore(store);
|
||||
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
export type AppDispatch = typeof store.dispatch;
|
||||
|
||||
export const useAppDispatch = () => useDispatch<AppDispatch>();
|
||||
Reference in New Issue
Block a user