Skip to content

Commit

Permalink
remove unused funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikochiko committed Nov 12, 2024
1 parent 0a27f1a commit 5bc3c42
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 121 deletions.
15 changes: 0 additions & 15 deletions workspaces/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,6 @@ def workspaces_page(user: AppUser, session: dict):
render_workspace_by_membership(membership)


def render_workspace_creation_view(user: AppUser):
gui.write(f"# {icons.company} Create an Workspace", unsafe_allow_html=True)

workspace = Workspace(created_by=user)
render_workspace_create_or_edit_form(workspace, user)

if gui.button("Create"):
try:
workspace.create_with_owner()
except ValidationError as e:
gui.write("\n".join(e.messages), className="text-danger")
else:
gui.rerun()


def render_workspace_by_membership(membership: WorkspaceMembership):
"""
membership object has all the information we need:
Expand Down
106 changes: 0 additions & 106 deletions workspaces/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,109 +206,3 @@ def get_default_name_for_new_workspace(user: AppUser, suffix: str = "") -> str:
return f"{email_domain_prefix} Team"

return f"{user.first_name_possesive()} Team Workspace" + suffix


def render_workspace_creation_dialog(
ref: gui.ConfirmDialogRef,
*,
user: AppUser,
session: dict,
) -> Workspace | None:
step_2_ref = gui.use_confirm_dialog(
key="--create-workspace-step-2", close_on_confirm=False
)

if ref.is_open:
_render_workspace_creation_dialog_step_1(ref, user=user, session=session)
if step_2_ref.is_open:
_render_workspace_creation_dialog_step_2(step_2_ref, user=user, session=session)

if ref.pressed_confirm:
step_2_ref.set_open(True)
raise gui.RerunException()
if step_2_ref.pressed_confirm:
ref.set_open(False)
return get_current_workspace(user, session)


def _render_workspace_creation_dialog_step_1(
ref: gui.ConfirmDialogRef, *, user: AppUser, session: dict
):
from routers.account import account_route

with gui.confirm_dialog(
ref=ref,
modal_title="#### Create Team Workspace",
confirm_label="Create Workspace",
):
gui.caption(
"Workspaces allow you to collaborate with team members with a shared payment method."
)

workspace_name = gui.text_input(
"##### Name",
value=get_default_name_for_new_workspace(user),
)
gui.write("##### Billing")
gui.caption(
"Your first workspace gets 500 ($5) Credits. Add a payment method for shared billing."
)
add_payment_method_button = gui.button("Add Payment Method", type="link")

if not ref.pressed_confirm and not add_payment_method_button:
return

workspace = create_workspace_with_defaults(user, name=workspace_name)
set_current_workspace(session, workspace.id)

if add_payment_method_button:
raise gui.RedirectException(get_route_path(account_route))


def _render_workspace_creation_dialog_step_2(
ref: gui.ConfirmDialogRef, *, user: AppUser, session: dict
):
workspace = get_current_workspace(user, session)
with gui.confirm_dialog(
ref=ref,
modal_title=f"#### Invite members to {workspace.display_name()}",
confirm_label="Done",
cancel_className="d-none", # hack
):
gui.write("##### Invite Members")
with gui.div(className="d-flex"):
with gui.div(className="flex-grow-1"):
email = gui.text_input("")
pressed_invite = gui.button(f"{icons.send} Invite", type="tertiary")

if pressed_invite:
try:
WorkspaceInvite.objects.create_and_send_invite(
workspace=workspace,
email=email,
user=user,
defaults=dict(role=WorkspaceRole.ADMIN),
)
except ValidationError as e:
gui.error("\n".join(e.messages))
else:
gui.success("Invitation sent!")

email_domain = user.email and user.email.split("@")[-1]
if email_domain and email_domain.lower() not in COMMON_EMAIL_DOMAINS:
gui.write("##### Email Domain")
gui.caption(
"Anyone with this email domain will be automatically added as member to this workspace"
)
workspace.domain_name = gui.selectbox(
label="",
options=[email_domain],
format_func=lambda s: s and f"@{s}" or "—" * 3,
value=email_domain,
allow_none=True,
)

if ref.pressed_confirm:
if workspace.domain_name:
workspace.save(update_fields=["domain_name"])
ref.set_open(False)

0 comments on commit 5bc3c42

Please sign in to comment.