Skip to content

Commit

Permalink
implementing setting last_login to unban date
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderUngefug committed Jun 12, 2024
1 parent 874cec7 commit f80168f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def banned
private

def user_params
params.require(:user).permit(:status)
params.require(:user).permit(:status, :last_login)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function BannedPendingRow({ user, pendingTable }) {
</div>
<Stack>
<span className="text-dark fw-bold"> {user.name} </span>
<span className="small"> { t('admin.manage_users.user_created_at', { localizedTime }) }</span>
<span className="small"> {t('admin.manage_users.user_created_at', { localizedTime })}</span>
</Stack>
</Stack>
</td>
Expand All @@ -68,7 +68,7 @@ export default function BannedPendingRow({ user, pendingTable }) {
</Dropdown.Item>
</>
) : (
<Dropdown.Item onClick={() => updateUserStatus.mutate({ id: user.id, status: 'active' })}>
<Dropdown.Item onClick={() => updateUserStatus.mutate({ id: user.id, status: 'active', last_login: new Date().toDateString() })}>
<CheckIcon className="hi-s me-2" />
{t('admin.manage_users.unban')}
</Dropdown.Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ export default function useUpdateUserStatus() {
const { t } = useTranslation();
const queryClient = useQueryClient();

const createPayload = (data) => {
const user = { status: data.status }
if (data.last_login) {
user.last_login = data.last_login
}
return { user };
}

return useMutation(
(data) => axios.patch(`/admin/users/${data.id}.json`, { user: { status: data.status } }),
(data) => axios.patch(`/admin/users/${data.id}.json`, createPayload(data)),
{
onSuccess: () => {
queryClient.invalidateQueries(['getPendingUsers']);
Expand Down

0 comments on commit f80168f

Please sign in to comment.