Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Switch between internal / external application #583

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion backend/clubs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,8 +2607,9 @@ class ClubApplicationSerializer(ClubRouteMixin, serializers.ModelSerializer):
active = serializers.SerializerMethodField("get_active", read_only=True)

def get_external_url(self, obj):
ext_url = self.context["request"].data.get("external_url")
default_url = f"https://pennclubs.com/club/{obj.club.code}/application/{obj.pk}"
return obj.external_url if obj.external_url else default_url
return ext_url if ext_url else default_url

def get_cycle(self, obj):
return obj.application_cycle.name if obj.application_cycle else obj.season
Expand Down Expand Up @@ -2644,6 +2645,12 @@ def get_image_url(self, obj):
def validate(self, data):
acceptance_template = data.get("acceptance_email", "")
rejection_template = data.get("rejection_email", "")
external_url = self.context["request"].data.get("external_url")

if not external_url and not (acceptance_template and rejection_template):
raise serializers.ValidationError(
"Your application email templates cannot be empty!"
)

if not ClubApplication.validate_template(
acceptance_template
Expand Down
77 changes: 54 additions & 23 deletions frontend/components/ClubEditPage/ApplicationsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
OBJECT_NAME_SINGULAR,
OBJECT_NAME_TITLE_SINGULAR,
} from '../../utils/branding'
import { Icon, Modal, Text } from '../common'
import { Checkbox, CheckboxLabel, Icon, Modal, Text } from '../common'
import {
ApplicationUpdateTextField,
CheckboxField,
Expand Down Expand Up @@ -203,6 +203,7 @@ export default function ApplicationsCard({ club }: Props): ReactElement {
const [show, setShow] = useState(false)
const showModal = () => setShow(true)
const hideModal = () => setShow(false)
const [isExternal, setIsExternal] = useState(false)
const [applicationName, setApplicationName] = useState('')
const [committees, setCommittees] = useState<{
label: string
Expand Down Expand Up @@ -346,34 +347,64 @@ export default function ApplicationsCard({ club }: Props): ReactElement {
club.is_wharton ? 'Read-only.' : ''
}`}
/>
<Field
name="external_url"
as={TextField}
type="url"
helpText={`The external URL where students can apply for your ${OBJECT_NAME_SINGULAR}.`}
/>
<Field
name="committees"
as={CreatableMultipleSelectField}
initialValues={committees}
helpText={`If your ${OBJECT_NAME_SINGULAR} has multiple committees to which students can apply, list them here. NOTE: you won't be able to edit this field after applications open.`}
/>
<Field
name="acceptance_email"
as={ApplicationUpdateTextField}
initialValues={
"<html> <body> <p> Congratulations {{ name }}! You've been accepted to {{ committee }} because {{reason}}! </p> </body> </html>"
}
helpText={`Acceptance email for your ${OBJECT_NAME_SINGULAR}.`}
/>
<Field
name="rejection_email"
as={ApplicationUpdateTextField}
initialValues={
"<html> <body> <p> Sorry {{ name }}, You've been rejected because {{ reason }}! </p> </body> </html>"
}
helpText={`Rejection email for your ${OBJECT_NAME_SINGULAR}.`}
/>

<div className="field is-horizontal">
<div className="field-label">
<label className="label">Use External Application?</label>
</div>
<div className="field-body">
<div className="field">
<div className="control">
<Checkbox
id="is_external"
checked={isExternal}
onChange={() => setIsExternal(!isExternal)}
/>
<CheckboxLabel
htmlFor="is_external"
style={{
marginLeft: '8px',
}}
>
Make this an external application
</CheckboxLabel>
</div>
</div>
</div>
</div>
{isExternal ? (
<Field
name="external_url"
as={TextField}
type="url"
helpText={`The external URL where students can apply for your ${OBJECT_NAME_SINGULAR}.`}
/>
) : (
<>
<Field
name="acceptance_email"
as={ApplicationUpdateTextField}
initialValues={
"<html> <body> <p> Congratulations {{ name }}! You've been accepted to {{ committee }} because {{reason}}! </p> </body> </html>"
}
helpText={`Acceptance email for your ${OBJECT_NAME_SINGULAR}.`}
/>
<Field
name="rejection_email"
as={ApplicationUpdateTextField}
initialValues={
"<html> <body> <p> Sorry {{ name }}, You've been rejected because {{ reason }}! </p> </body> </html>"
}
helpText={`Rejection email for your ${OBJECT_NAME_SINGULAR}.`}
/>
</>
)}
</>
}
confirmDeletion={true}
Expand Down
Loading