Skip to content

Commit f46598d

Browse files
authored
feat: implement add clipboard functionality for cause URL (#605)
1 parent e8f57a1 commit f46598d

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

backend/donations/views/ngo_account/causes.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,23 @@ def get_context_data(self, **kwargs):
3030

3131
ngo: Ngo = context["ngo"]
3232

33+
cause: Cause | None = self.get_cause(ngo=ngo, cause_id=kwargs.get("cause_id"))
34+
context["cause"] = cause
35+
if cause:
36+
context["absolute_cause_url"] = self.get_absolute_cause_url(cause_slug=cause.slug)
37+
3338
context["info_banner_items"] = self.get_ngo_cause_banner_list_items(ngo)
3439
context["visibility_choices"] = CauseVisibilityChoices.as_str_pretty()
3540
context["ngo_has_tax_account"] = ngo.has_online_tax_account
3641

3742
return context
3843

44+
def get_absolute_cause_url(self, cause_slug: str) -> str:
45+
return self.request.build_absolute_uri(reverse("twopercent", kwargs={"cause_slug": cause_slug}))
46+
47+
def get_cause(self, *, ngo: Ngo, cause_id: int | None) -> Cause | None:
48+
raise NotImplementedError
49+
3950
def get_ngo_cause_banner_list_items(self, ngo: Ngo) -> list[str]:
4051
banner_list_items = [
4152
_("Organization name: ") + ngo.name,
@@ -176,6 +187,9 @@ def get_context_data(self, **kwargs):
176187

177188
return context
178189

190+
def get_cause(self, *, ngo: Ngo, cause_id: int | None) -> Cause | None:
191+
return None
192+
179193
@method_decorator(login_required(login_url=reverse_lazy("login")))
180194
def get(self, request, *args, **kwargs):
181195
user: User = request.user
@@ -208,7 +222,7 @@ def get_context_data(self, **kwargs):
208222

209223
page_title = _("Edit cause")
210224

211-
context["cause"] = self.get_cause(cause_id=kwargs["cause_id"], ngo=context["ngo"])
225+
context["cause"] = self.get_cause(ngo=context["ngo"], cause_id=kwargs["cause_id"])
212226
context["django_form"] = CauseForm(instance=context["cause"], for_main_cause=self.is_main_cause)
213227

214228
context["page_title"] = f'{page_title}: "{context["cause"].name}"'
@@ -224,11 +238,8 @@ def get_context_data(self, **kwargs):
224238

225239
return context
226240

227-
def get_cause(self, cause_id: int, ngo: Ngo) -> Cause:
228-
if not ngo:
229-
raise Http404
230-
231-
if not cause_id:
241+
def get_cause(self, *, ngo: Ngo, cause_id: int | None) -> Cause | None:
242+
if not (ngo and cause_id):
232243
raise Http404
233244

234245
cause = Cause.objects.filter(pk=cause_id, ngo=ngo).first()

backend/donations/views/ngo_account/my_organization.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.contrib import messages
33
from django.contrib.auth.decorators import login_required
44
from django.core.exceptions import PermissionDenied
5+
from django.http import Http404
56
from django.shortcuts import redirect, render
67
from django.urls import reverse, reverse_lazy
78
from django.utils.decorators import method_decorator
@@ -164,7 +165,6 @@ def __init__(self, *args, **kwargs):
164165
def get_context_data(self, **kwargs):
165166
context = super().get_context_data(is_main_cause=True, **kwargs)
166167

167-
context["cause"] = self.get_main_cause(context.get("ngo"))
168168
context["is_main_cause"] = self.is_main_cause
169169

170170
context["django_form"] = CauseForm(instance=context["cause"], for_main_cause=self.is_main_cause)
@@ -179,7 +179,10 @@ def get_context_data(self, **kwargs):
179179
context["active_tab"] = self.tab_title
180180
return context
181181

182-
def get_main_cause(self, ngo: Ngo) -> Cause:
182+
def get_cause(self, *, ngo: Ngo, cause_id: int | None) -> Cause | None:
183+
if not ngo:
184+
raise Http404
185+
183186
return Cause.objects.filter(ngo=ngo, is_main=True).first()
184187

185188
@method_decorator(login_required(login_url=reverse_lazy("login")))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{% extends "components/copy-to-clipboard/base.html" %}
2+
3+
{% load i18n %}
4+
5+
6+
{% block clickable_content %}
7+
<span class="flex items-center justify-center gap-x-1.5 ">
8+
<svg
9+
xmlns="http://www.w3.org/2000/svg"
10+
viewBox="0 0 {{ view_box_size }} {{ view_box_size }}"
11+
fill="currentColor"
12+
class="size-5">
13+
14+
{% if icon_path %}
15+
<path d="{{ icon_path }}"/>
16+
{% else %}
17+
<path
18+
d="M12.232 4.232a2.5 2.5 0 0 1 3.536 3.536l-1.225 1.224a.75.75 0 0 0 1.061 1.06l1.224-1.224a4 4 0 0 0-5.656-5.656l-3 3a4 4 0 0 0 .225 5.865.75.75 0 0 0 .977-1.138 2.5 2.5 0 0 1-.142-3.667l3-3Z"/>
19+
<path
20+
d="M11.603 7.963a.75.75 0 0 0-.977 1.138 2.5 2.5 0 0 1 .142 3.667l-3 3a2.5 2.5 0 0 1-3.536-3.536l1.225-1.224a.75.75 0 0 0-1.061-1.06l-1.224 1.224a4 4 0 1 0 5.656 5.656l3-3a4 4 0 0 0-.225-5.865Z"/>
21+
{% endif %}
22+
</svg>
23+
24+
{% if button_text %}
25+
{{ button_text }}
26+
{% else %}
27+
{{ block.super }}
28+
{% endif %}
29+
</span>
30+
31+
{% endblock %}

backend/templates/v2/ngo-account/components/form-title.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ <h2 class="text-2xl text-gray-900 lg:col-span-2 text-bold">
88

99
<div class="grid items-center justify-end gap-2 sm:flex md:col-span-2">
1010
{% if not hide_public_page_button and ngo.can_create_causes and cause %}
11+
{% include "components/copy-to-clipboard/icon_and_text.html" with clipboard_input=absolute_cause_url div_classes="px-3 py-2 text-sm font-semibold text-gray-700 no-underline border-2 rounded-md border-gray-300 bg-white hover:bg-gray-200 hover:cursor-pointer" %}
12+
1113
<a
1214
href="{% url 'twopercent' cause_slug=cause.slug %}"
1315
target="_blank"
@@ -24,7 +26,7 @@ <h2 class="text-2xl text-gray-900 lg:col-span-2 text-bold">
2426
<path
2527
stroke-linecap="round"
2628
stroke-linejoin="round"
27-
d="M13.5 6H5.25A2.25 2.25 0 0 0 3 8.25v10.5A2.25 2.25 0 0 0 5.25 21h10.5A2.25 2.25 0 0 0 18 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25" />
29+
d="M13.5 6H5.25A2.25 2.25 0 0 0 3 8.25v10.5A2.25 2.25 0 0 0 5.25 21h10.5A2.25 2.25 0 0 0 18 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25"/>
2830
</svg>
2931

3032
<span>
@@ -57,7 +59,7 @@ <h2 class="text-2xl text-gray-900 lg:col-span-2 text-bold">
5759
<path
5860
stroke-linecap="round"
5961
stroke-linejoin="round"
60-
d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" />
62+
d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3"/>
6163
</svg>
6264

6365
<span>

0 commit comments

Comments
 (0)