Skip to content

Commit

Permalink
Feat/payment history click (#721)
Browse files Browse the repository at this point in the history
* add modal for viewing payment history bounty, and fixed pagination issues

* changed == to ==
  • Loading branch information
elraphty authored Sep 20, 2023
1 parent 7f3361a commit 5cc055b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 26 deletions.
11 changes: 8 additions & 3 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,25 +503,30 @@ func (db database) GetAllBounties(r *http.Request) []BountyData {
keys := r.URL.Query()
tags := keys.Get("tags") // this is a string of tags separated by commas
offset, limit, sortBy, direction, search := utils.GetPaginationParams(r)

ms := []BountyData{}

orderQuery := ""
limitQuery := ""
searchQuery := ""

if sortBy != "" && direction != "" {
orderQuery = "ORDER BY " + "body." + sortBy + " " + direction
} else {
orderQuery = " ORDER BY " + "body." + sortBy + "" + "DESC"
}
if offset != 0 && limit != 0 {
if limit != 0 {
limitQuery = fmt.Sprintf("LIMIT %d OFFSET %d", limit, offset)
}
if search != "" {
searchQuery = fmt.Sprintf("WHERE LOWER(body.title) LIKE %s", "'%"+search+"%'")
}

rawQuery := "SELECT body.*, body.id as bounty_id, body.description as bounty_description, body.created as bounty_created, body.updated as bounty_updated, body.org_uuid, person.*, person.owner_alias as assignee_alias, person.id as assignee_id, person.description as assignee_description, person.created as assignee_created, person.updated as assignee_updated, owner.id as bounty_owner_id, owner.uuid as owner_uuid, owner.owner_pub_key as owner_key, owner.owner_alias as owner_alias, owner.description as owner_description, owner.price_to_meet as owner_price_to_meet, owner.unique_name as owner_unique_name, owner.tags as owner_tags, owner.img as owner_img, owner.created as owner_created, owner.updated as owner_updated, owner.last_login as owner_last_login, owner.owner_route_hint as owner_route_hint, owner.owner_contact_key as owner_contact_key, org.name as organization_name, org.uuid as organization_uuid, org.img as organization_img FROM public.bounty AS body LEFT OUTER JOIN public.people AS person ON body.assignee = person.owner_pub_key LEFT OUTER JOIN public.people as owner ON body.owner_id = owner.owner_pub_key LEFT OUTER JOIN public.organizations as org ON body.org_uuid = org.uuid"
query := "SELECT body.*, body.id as bounty_id, body.description as bounty_description, body.created as bounty_created, body.updated as bounty_updated, body.org_uuid, person.*, person.owner_alias as assignee_alias, person.id as assignee_id, person.description as assignee_description, person.created as assignee_created, person.updated as assignee_updated, owner.id as bounty_owner_id, owner.uuid as owner_uuid, owner.owner_pub_key as owner_key, owner.owner_alias as owner_alias, owner.description as owner_description, owner.price_to_meet as owner_price_to_meet, owner.unique_name as owner_unique_name, owner.tags as owner_tags, owner.img as owner_img, owner.created as owner_created, owner.updated as owner_updated, owner.last_login as owner_last_login, owner.owner_route_hint as owner_route_hint, owner.owner_contact_key as owner_contact_key, org.name as organization_name, org.uuid as organization_uuid, org.img as organization_img FROM public.bounty AS body LEFT OUTER JOIN public.people AS person ON body.assignee = person.owner_pub_key LEFT OUTER JOIN public.people as owner ON body.owner_id = owner.owner_pub_key LEFT OUTER JOIN public.organizations as org ON body.org_uuid = org.uuid"

theQuery := db.db.Raw(rawQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery)
allQuery := query + " " + searchQuery + " " + orderQuery + " " + limitQuery

theQuery := db.db.Raw(allQuery)

if tags != "" {
// pull out the tags and add them in here
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/form/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const OrgWrap = styled.div<WrapProps>`
height: inherit;
flex-direction: column;
align-content: center;
min-width: 500px;
min-width: 550px;
max-width: auto;
`;

Expand Down
14 changes: 7 additions & 7 deletions frontend/app/src/people/main/FocusView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const B = styled.div<BProps>`
overflow-y: auto;
box-sizing: border-box;
${EnvWithScrollBar({
thumbColor: '#5a606c',
trackBackgroundColor: 'rgba(0,0,0,0)'
})}
thumbColor: '#5a606c',
trackBackgroundColor: 'rgba(0,0,0,0)'
})}
`;
function FocusedView(props: FocusViewProps) {
const {
Expand Down Expand Up @@ -101,10 +101,10 @@ function FocusedView(props: FocusViewProps) {

const isTorSave = canEdit && main.isTorSave();

const userOrganizations = main.organizations.map((org: Organization) => ({
const userOrganizations = main.organizations.length ? main.organizations.map((org: Organization) => ({
label: toCapitalize(org.name),
value: org.uuid
}));
})) : [];

function isNotHttps(url: string | undefined) {
if (main.isTorSave() || url?.startsWith('http://')) {
Expand Down Expand Up @@ -369,8 +369,8 @@ function FocusedView(props: FocusViewProps) {
extraHTML={
ui.meInfo.verification_signature
? {
twitter: `<span>Post this to your twitter account to verify:</span><br/><strong>Sphinx Verification: ${ui.meInfo.verification_signature}</strong>`
}
twitter: `<span>Post this to your twitter account to verify:</span><br/><strong>Sphinx Verification: ${ui.meInfo.verification_signature}</strong>`
}
: {}
}
/>
Expand Down
41 changes: 37 additions & 4 deletions frontend/app/src/people/widgetViews/OrganizationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { Formik } from 'formik';
import { FormField, validator } from 'components/form/utils';
import { BountyRoles, BudgetHistory, Organization, PaymentHistory, Person } from 'store/main';
import MaterialIcon from '@material/react-material-icon';
import { Route, Router, Switch, useRouteMatch } from 'react-router-dom';
import { userHasRole } from 'helpers';
import { BountyModal } from 'people/main/bountyModal';
import history from '../../config/history';
import { Modal } from '../../components/common';
import { colors } from '../../config/colors';
import { nonWidgetConfigs } from '../utils/Constants';
Expand Down Expand Up @@ -145,6 +148,15 @@ const CheckLabel = styled.label`
margin: 0px;
`;

const ViewBounty = styled.p`
padding: 0px;
margin: 0px;
cursor: pointer;
font-size: 0.9rem;
color: green;
font-size: bold;
`;

const OrganizationDetails = (props: { close: () => void; org: Organization | undefined }) => {
const [loading, setIsLoading] = useState<boolean>(false);
const isMobile = useIsMobile();
Expand All @@ -168,6 +180,8 @@ const OrganizationDetails = (props: { close: () => void; org: Organization | und
const [lnInvoice, setLnInvoice] = useState('');
const [invoiceStatus, setInvoiceStatus] = useState(false);
const [amount, setAmount] = useState(1);
const { path, url } = useRouteMatch();


const pollMinutes = 2;

Expand Down Expand Up @@ -376,6 +390,14 @@ const OrganizationDetails = (props: { close: () => void; org: Organization | und
}
};

const viewBounty = async (bountyId: number) => {
ui.setBountyPerson(ui.meInfo?.id);

history.push({
pathname: `${url}/${bountyId}/${0}`
});
}

useEffect(() => {
getOrganizationUsers();
getOrganizationUsersCount();
Expand Down Expand Up @@ -567,8 +589,8 @@ const OrganizationDetails = (props: { close: () => void; org: Organization | und
style={
item.name === 'github_description' && !values.ticket_url
? {
display: 'none'
}
display: 'none'
}
: undefined
}
/>
Expand Down Expand Up @@ -738,16 +760,20 @@ const OrganizationDetails = (props: { close: () => void; org: Organization | und
<thead>
<tr>
<th>Sender</th>
<th>Recipient</th>
<th>Amount</th>
<th>Date</th>
<th></th>
</tr>
</thead>
<tbody>
{paymentsHistory.map((pay: PaymentHistory, i: number) => (
<tr key={i}>
<td className="ellipsis">{pay.sender_name}</td>
<td className="ellipsis">{pay.receiver_name}</td>
<td>{pay.amount} sats</td>
<td>{moment(pay.created).fromNow()}</td>
<td>{moment(pay.created).format('DD/MM/YY')}</td>
<td><ViewBounty onClick={() => viewBounty(pay.bounty_id)}>View bounty</ViewBounty></td>
</tr>
))}
</tbody>
Expand Down Expand Up @@ -798,7 +824,7 @@ const OrganizationDetails = (props: { close: () => void; org: Organization | und
<td>{b.amount} sats</td>
<td>{b.payment_type}</td>
<td>{b.status ? 'settled' : 'peending'}</td>
<td>{moment(b.created).fromNow()}</td>
<td>{moment(b.created).format('DD/MM/YY')}</td>
</tr>
))}
</tbody>
Expand All @@ -808,6 +834,13 @@ const OrganizationDetails = (props: { close: () => void; org: Organization | und
)}
</DetailsWrap>
<EuiGlobalToastList toasts={toasts} dismissToast={removeToast} toastLifeTimeMs={5000} />
<Router history={history}>
<Switch>
<Route path={`${path}/:wantedId/:wantedIndex`}>
<BountyModal basePath={url} />
</Route>
</Switch>
</Router>
</Container>
);
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/src/people/widgetViews/OrganizationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const Organizations = (props: { person: Person }) => {
const isMobile = useIsMobile();
const config = widgetConfigs['organizations'];
const formRef = useRef(null);
const isMyProfile = ui?.meInfo?.pubkey == props?.person?.owner_pubkey;
const isMyProfile = ui?.meInfo?.pubkey === props?.person?.owner_pubkey;

const schema = [...config.schema];

Expand Down Expand Up @@ -247,8 +247,8 @@ const Organizations = (props: { person: Person }) => {
style={
item.name === 'github_description' && !values.ticket_url
? {
display: 'none'
}
display: 'none'
}
: undefined
}
/>
Expand Down
18 changes: 10 additions & 8 deletions frontend/app/src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ export class MainStore {
@persist('list')
peopleWanteds: PersonWanted[] = [];

setPeopleWanteds(wanteds: PersonWanted[]) {
@action setPeopleWanteds(wanteds: PersonWanted[]) {
this.peopleWanteds = wanteds;
}

Expand Down Expand Up @@ -771,19 +771,19 @@ export class MainStore {

// for search always reset page
if (queryParams && queryParams.resetPage) {
this.peopleWanteds = ps3;
this.setPeopleWanteds(ps3);
uiStore.setPeopleWantedsPageNumber(1);
} else {
// all other cases, merge
this.peopleWanteds = this.doPageListMerger(
const wanteds = this.doPageListMerger(
this.peopleWanteds,
ps3,
(n: any) => uiStore.setPeopleWantedsPageNumber(n),
queryParams,
'wanted'
);
this.setPeopleWanteds(wanteds);
}
this.setPeopleWanteds(ps3);
return ps3;
} catch (e) {
console.log('fetch failed getPeopleWanteds: ', e);
Expand All @@ -793,7 +793,7 @@ export class MainStore {

personAssignedWanteds: PersonWanted[] = [];

setPersonWanteds(wanteds: PersonWanted[]) {
@action setPersonWanteds(wanteds: PersonWanted[]) {
this.personAssignedWanteds = wanteds;
}

Expand Down Expand Up @@ -840,7 +840,7 @@ export class MainStore {

createdWanteds: PersonWanted[] = [];

setCreatedWanteds(wanteds: PersonWanted[]) {
@action setCreatedWanteds(wanteds: PersonWanted[]) {
this.createdWanteds = wanteds;
}

Expand Down Expand Up @@ -953,17 +953,19 @@ export class MainStore {

// for search always reset page
if (queryParams && queryParams.resetPage) {
this.peopleWanteds = ps3;
this.setPeopleWanteds(ps3);
uiStore.setPeopleWantedsPageNumber(1);
} else {
// all other cases, merge
this.peopleWanteds = this.doPageListMerger(
const wanteds = this.doPageListMerger(
this.peopleWanteds,
ps3,
(n: any) => uiStore.setPeopleWantedsPageNumber(n),
queryParams,
'wanted'
);

this.setPeopleWanteds(wanteds);
}
return ps3;
} catch (e) {
Expand Down

0 comments on commit 5cc055b

Please sign in to comment.