1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-20 02:00:49 +00:00

Allow giving points to arbitrary users

This commit is contained in:
Ash Keel 2021-05-18 13:47:17 +02:00
parent 622abb0b5c
commit e47e94f4ed
No known key found for this signature in database
GPG key ID: CF2CC050478BD7E5
2 changed files with 21 additions and 2 deletions

View file

@ -230,7 +230,7 @@ export const setUserPoints = createAsyncThunk(
const { api } = getState() as { api: APIState };
const entry: LoyaltyPointsEntry = { points };
if (relative) {
entry.points += api.loyalty.users[user].points ?? 0;
entry.points += api.loyalty.users[user]?.points ?? 0;
}
return api.client.putJSON(loyaltyPointsPrefix + user, entry);
},

View file

@ -40,7 +40,7 @@ function UserModal({
const [user, setUser] = useState(initialData.user);
const [entry, setEntry] = useState(initialData.entry);
const userEditable = initialData.user !== '';
const userEditable = initialData.user === '';
const nameValid = user !== '';
const pointsValid = Number.isFinite(entry.points);
@ -133,6 +133,7 @@ export default function LoyaltyUserListPage(
const [page, setPage] = useState(0);
const [usernameFilter, setUsernameFilter] = useState('');
const [editModal, setEditModal] = useState<UserData>(null);
const [createModal, setCreateModal] = useState<boolean>(false);
const changeSort = (key: 'user' | 'points') => {
if (sorting.key === key) {
@ -180,9 +181,22 @@ export default function LoyaltyUserListPage(
dispatch(setUserPoints({ user, points: entry.points, relative: false }));
setEditModal(null);
};
const assignPoints = ({ entry, user }: UserData) => {
console.log(user, entry);
dispatch(setUserPoints({ user, points: entry.points, relative: true }));
setCreateModal(false);
};
return (
<>
<UserModal
title="Give points to user"
confirmText="Give"
active={createModal}
onConfirm={(entry) => assignPoints(entry)}
initialData={{ user: '', entry: { points: 0 } }}
onClose={() => setCreateModal(false)}
/>
{editModal ? (
<UserModal
title="Modify balance"
@ -207,6 +221,11 @@ export default function LoyaltyUserListPage(
}
/>
</div>
<div className="field">
<a className="button is-small" onClick={() => setCreateModal(true)}>
Give points to user
</a>
</div>
<PageList
current={page + 1}
min={1}