Skip to content

Commit

Permalink
Add reason for denying Loop access "no longer active"#625
Browse files Browse the repository at this point in the history
  • Loading branch information
lil5 committed Nov 20, 2023
1 parent a497e7e commit 03e6c07
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
1 change: 1 addition & 0 deletions frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
"reasonForDenyingJoin": "Please give a reason to deny the request",
"tooFarAway": "Too far away",
"differentSizes": "Different sizes",
"loopNotActive": "Loop not active",
"other": "Other",
"events": "Events",
"previousEvents": "Previous Events",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export enum UnapprovedReason {
OTHER = "other",
TOO_FAR_AWAY = "too_far_away",
SIZES_GENDERS = "sizes_genders",
LOOP_NOT_ACTIVE = "loop_not_active",
}

export function chainDeleteUnapproved(
Expand Down
49 changes: 48 additions & 1 deletion frontend/src/pages/ChainMemberList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default function ChainMemberList() {
const [route, setRoute] = useState<UID[] | null>(null);
const [routeWasOptimized, setRouteWasOptimized] = useState<boolean>(false);
const [previousRoute, setPreviousRoute] = useState<UID[] | null>(null);
const [changingPublishedAuto, setChangingPublishedAuto] = useState(false);

const [participantsSortBy, setParticipantsSortBy] =
useState<ParticipantsSortBy>("date");
Expand Down Expand Up @@ -180,6 +181,38 @@ export default function ChainMemberList() {
}
}

function handleReasonLoopNotActive() {
if (!chain?.published) return;

let oldValueOpenToNewMembers = chain?.open_to_new_members || false;
let oldValuePublished = chain?.published || false;
setPublished(false);
setOpenToNewMembers(false);
const chainUpdateBody = {
uid: chainUID,
published: false,
open_to_new_members: false,
};
chainUpdate(chainUpdateBody)
.then(() => {
setChain((s) => ({
...(s as Chain),
...chainUpdateBody,
}));

setChangingPublishedAuto(true);
setTimeout(() => {
setChangingPublishedAuto(false);
}, 1500);
})
.catch((err: any) => {
console.error("Error updating chain: ", err);
setError(err?.data || `Error: ${JSON.stringify(err)}`);
setPublished(oldValuePublished);
setOpenToNewMembers(oldValueOpenToNewMembers);
});
}

function onAddCoHost(e: FormEvent) {
e.preventDefault();
if (!chain) return;
Expand Down Expand Up @@ -504,7 +537,11 @@ export default function ChainMemberList() {

{isUserAdmin || authUser?.is_root_admin ? (
<>
<div className="mt-4">
<div
className={`mt-4 ${
changingPublishedAuto ? "bg-yellow/[.6]" : ""
}`}
>
<div className="form-control w-full">
<label className="cursor-pointer label">
<span className="label-text">{t("published")}</span>
Expand Down Expand Up @@ -700,6 +737,7 @@ export default function ChainMemberList() {
unapprovedUsers={unapprovedUsers}
chain={chain}
refresh={refresh}
onReasonLoopNotActive={handleReasonLoopNotActive}
/>
) : selectedTable === "participants" ? (
<ParticipantsTable
Expand Down Expand Up @@ -832,6 +870,7 @@ function ApproveTable(props: {
unapprovedUsers: User[];
chain: Chain;
refresh: () => Promise<void>;
onReasonLoopNotActive: () => void;
}) {
const { t, i18n } = useTranslation();
const { addToastError, addModal } = useContext(ToastContext);
Expand Down Expand Up @@ -904,6 +943,14 @@ function ApproveTable(props: {
chainDeleteUnapprovedReason(UnapprovedReason.SIZES_GENDERS);
},
},
{
text: t("loopNotActive"),
type: "secondary",
fn: () => {
chainDeleteUnapprovedReason(UnapprovedReason.LOOP_NOT_ACTIVE);
props.onReasonLoopNotActive();
},
},
{
text: t("other"),
type: "secondary",
Expand Down
9 changes: 5 additions & 4 deletions server/internal/controllers/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (
)

const (
UnapprovedReasonOther = "other"
UnapprovedReasonOutOfAria = "out_of_aria"
UnapprovedReasonSizesGenders = "sizes_genders"
UnapprovedReasonOther = "other"
UnapprovedReasonOutOfAria = "out_of_aria"
UnapprovedReasonSizesGenders = "sizes_genders"
UnapprovedReasonLoopNotActive = "loop_not_active"
)

type ChainCreateRequestBody struct {
Expand Down Expand Up @@ -527,7 +528,7 @@ func ChainDeleteUnapproved(c *gin.Context) {
var query struct {
UserUID string `form:"user_uid" binding:"required,uuid"`
ChainUID string `form:"chain_uid" binding:"required,uuid"`
Reason string `form:"reason" binding:"required,oneof='other' 'too_far_away' 'sizes_genders'"`
Reason string `form:"reason" binding:"required,oneof='other' 'too_far_away' 'sizes_genders' 'loop_not_active'"`
}
if err := c.ShouldBindQuery(&query); err != nil {
c.String(http.StatusBadRequest, err.Error())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
<p>Unfortunately, your request to join The {{ .ChainName }} Loop has been denied for another reason.</p>

<p>Go to the website: www.clothingloop.org and start a new Loop.</p>
{{ else if eq .Reason "loop_not_active" }}
<p>Unfortunately, your request to join The {{ .ChainName }} Loop has been denied as this Loop is no longer active.</p>
{{ end }}

0 comments on commit 03e6c07

Please sign in to comment.