Fakultas Ilmu Komputer UI

Commit b2f07c00 authored by Muhammad Fairuzi Teguh's avatar Muhammad Fairuzi Teguh
Browse files

Merge branch 'warmfix-iruz' into 'staging'

Warmfix iruz

See merge request !122
parents 654cbdc6 78a52a2e
Pipeline #50008 passed with stages
in 13 minutes and 4 seconds
from django.contrib import admin
from django.conf import settings
from main.admin import InputFilter
from donor.models import DaftarDonor, JadwalDonor
from django.utils.translation import gettext_lazy as _
from django.http import HttpResponse
from donor.models import JadwalDonor, DaftarDonor
from django.conf import settings
from django.db.models import Q
from django.contrib import admin
def download_jadwaldonor(modeladmin, request, queryset):
......@@ -73,6 +75,18 @@ class JadwalDonorAdmin(admin.ModelAdmin):
js = [settings.MEDIA_URL+'/js/acara_donor_custom_admin.js', ]
class JadwalDonorFilter(InputFilter):
parameter_name = 'lokasi_donor'
title = _('lokasi donor')
def queryset(self, request, queryset):
if self.value() is not None:
lokasi_donor = self.value()
return queryset.filter(
Q(jadwal_donor__location__contains=lokasi_donor)
)
@admin.register(DaftarDonor)
class DaftarDonorAdmin(admin.ModelAdmin):
list_display = ('user', 'has_attended', 'get_goldar', 'jadwal_donor')
......@@ -124,7 +138,7 @@ class DaftarDonorAdmin(admin.ModelAdmin):
'menderita_pendarahan',
'seks_dengan_orang_afrika',
'tinggal_di_afrika')
list_filter = ('has_attended', 'user__profile__blood_type')
list_filter = ('has_attended', JadwalDonorFilter, 'jadwal_donor__time_start', 'user__profile__blood_type')
def get_goldar(self, obj):
return obj.user.profile.blood_type
......
......@@ -38,6 +38,24 @@ class UserAdmin(DjangoUserAdmin):
js = [settings.MEDIA_URL+'/js/user_custom_admin.js', ]
class InputFilter(admin.SimpleListFilter):
template = 'admin/input_filter.html'
def lookups(self, request, model_admin):
# Dummy, required to show the filter.
return ((),)
def choices(self, changelist):
# Grab only the "all" option.
all_choice = next(super().choices(changelist))
all_choice['query_parts'] = (
(k, v)
for k, v in changelist.get_filters_params().items()
if k != self.parameter_name
)
yield all_choice
@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
list_display = ('user', 'district', 'address', 'age', 'sex', 'blood_type')
......
{% load i18n %}
<h3>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3>
<ul>
<li>
{% with choices.0 as all_choice %}
<form method="GET" action="">
{% for k, v in all_choice.query_parts %}
<input type="hidden" name="{{ k }}" value="{{ v }}" />
{% endfor %}
<input type="text"
value="{{ spec.value|default_if_none:'' }}"
name="{{ spec.parameter_name }}"/>
{% if not all_choice.selected %}
<strong><a href="{{ all_choice.query_string }}">x {% trans 'Remove' %}</a></strong>
{% endif %}
</form>
{% endwith %}
</li>
</ul>
\ No newline at end of file
This diff is collapsed.
......@@ -13,7 +13,7 @@
"@material-ui/pickers": "^3.2.10",
"apexcharts": "^3.18.1",
"bootstrap": "^4.4.1",
"gatsby": "^2.19.7",
"gatsby": "^2.18.25",
"gatsby-plugin-offline": "^3.0.32",
"gatsby-plugin-page-creator": "^2.2.4",
"gatsby-plugin-react-helmet": "^3.1.21",
......@@ -56,7 +56,7 @@
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^1.7.0",
"gatsby-cli": "^2.10.2",
"gatsby-cli": "^2.10.13",
"identity-obj-proxy": "^3.0.0",
"jest": "^25.1.0",
"prettier": "^1.19.1",
......
......@@ -7,7 +7,7 @@ import ModalCompleteProfile from "./complete-profile"
import { withAuthenticated } from "./authenticated-only"
import moment from "moment"
const ModalGoogleCompleteProfile = ({ show, handleClose }) => {
const ModalGoogleCompleteProfile = ({ show, handleClose, handleSuccess }) => {
const { user, logout, getAndSetUserProfile } = useAuth()
const { control, register, handleSubmit, errors } = useForm({
......@@ -24,10 +24,10 @@ const ModalGoogleCompleteProfile = ({ show, handleClose }) => {
data.birthdate = moment(data.birthdate).format("YYYY-MM-DD")
await postUserProfile(data)
.then(() => {
.then(async () => {
window.alert("Profil Anda sudah disimpan.")
getAndSetUserProfile()
handleClose()
const newUser = await getAndSetUserProfile()
handleSuccess(newUser)
})
.catch(error => {
if (error.response) {
......
......@@ -16,8 +16,8 @@ const ModalLogin = ({ show, handleClose, handleSuccess }) => {
setLoginError(null)
setIsLoadingLogin(true)
try {
await login(data.email, data.password)
handleSuccess()
const user = await login(data.email, data.password)
handleSuccess(user)
} catch (error) {
const message = error.response
? "Email atau password salah."
......@@ -34,8 +34,8 @@ const ModalLogin = ({ show, handleClose, handleSuccess }) => {
setLoginError(null)
setIsLoadingLogin(true)
try {
await loginOAuth(data.tokenId)
handleSuccess()
const user = await loginOAuth(data.tokenId)
handleSuccess(user)
} catch (error) {
const message = error.response
? error.response.data.detail
......
......@@ -36,6 +36,7 @@ const AuthProvider = ({ children, ...otherProps }) => {
} else {
toggleShowModalGoogleCompleteProfile(false)
}
return newUser
} catch (error) {
// do nothing if the token is invalid
console.log(error)
......@@ -52,7 +53,7 @@ const AuthProvider = ({ children, ...otherProps }) => {
const refresh_token = result.data.refresh
setRefreshToken(refresh_token)
axios.defaults.headers.common = { Authorization: `Bearer ${access_token}` }
getAndSetUserProfile()
return await getAndSetUserProfile()
}
const loginOAuth = async tokenId => {
const result = await postUserLoginOAuth(tokenId)
......@@ -60,7 +61,7 @@ const AuthProvider = ({ children, ...otherProps }) => {
const refresh_token = result.data.refresh
setRefreshToken(refresh_token)
axios.defaults.headers.common = { Authorization: `Bearer ${access_token}` }
getAndSetUserProfile()
return await getAndSetUserProfile()
}
const loginToken = access_token => {
axios.defaults.headers.common = { Authorization: `Bearer ${access_token}` }
......@@ -132,9 +133,12 @@ const AuthProvider = ({ children, ...otherProps }) => {
<ModalLogin
show={showModalLogin}
handleClose={toggleShowModalLogin}
handleSuccess={() => {
handleSuccess={newUser => {
toggleShowModalLogin()
if (newUser.profile.body_weight) {
nextActionLogin()
setNextActionLogin(() => noop)
}
}}
/>
<ModalRegister
......@@ -148,6 +152,11 @@ const AuthProvider = ({ children, ...otherProps }) => {
<ModalGoogleCompleteProfile
show={showModalGoogleCompleteProfile}
handleClose={toggleShowModalGoogleCompleteProfile}
handleSuccess={newUser => {
toggleShowModalGoogleCompleteProfile(false)
nextActionLogin()
setNextActionLogin(() => noop)
}}
/>
<ModalEventDonorSubmission
show={showModalEventDonorSubmission}
......
......@@ -124,9 +124,7 @@ describe(`JadwalDonor`, () => {
getListJadwalDonor.mockResolvedValue({
data: [jadwal_donor],
})
getAgendaDonor
.mockResolvedValueOnce({ data: [] })
.mockResolvedValueOnce({ data: [] })
getAgendaDonor.mockResolvedValue({ data: [] })
render(<JadwalDonorPage />)
fireEvent.click(await screen.findByText("Donor"))
await doSuccessfulLogin()
......@@ -141,7 +139,7 @@ describe(`JadwalDonor`, () => {
})
getAgendaDonor
.mockResolvedValueOnce({ data: [] })
.mockResolvedValueOnce({ data: [jadwal_donor] })
.mockResolvedValue({ data: [jadwal_donor] })
window.alert = jest.fn()
render(<JadwalDonorPage />)
fireEvent.click(await screen.findByText("Donor"))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment