Yodlee page in ssr.

This commit is contained in:
2023-05-13 22:51:03 -07:00
parent 8dca622947
commit b9ae20125b
19 changed files with 417 additions and 160 deletions

View File

@@ -230,91 +230,93 @@
(let [vendor (dc/pull (dc/db conn) '[* {:vendor/legal-entity-1099-type [:db/ident]
:vendor/legal-entity-tin-type [:db/ident]}] (Long/parseLong (:vendor-id (:params request))))] ;; TODO perms
(html-response
(com/modal {}
[:form {:hx-post (str (bidi/path-for ssr-routes/only-routes
:company-1099-vendor-save
:request-method :post
:vendor-id (Long/parseLong (:vendor-id (:params request)))))
:hx-target "#vendor-table"
:hx-swap "outerHTML swap:300ms"}
[:fieldset {:class "hx-disable"}
(com/modal-card {}
[:div.flex [:div.p-2 "Vendor 1099 Info"] [:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600 (:vendor/name vendor)]]
[:div.space-y-6
[:div.grid.grid-cols-6.gap-4
[:h4.text-xl.border-b.col-span-6 "Address"]
[:div.col-span-6
(com/field {:label "Street 1"}
(com/text-input {:name (path->name [:vendor/address :address/street1])
:value (-> vendor :vendor/address :address/street1)
:placeholder "1700 Pennsylvania Ave"
:autofocus true}))]
[:div.col-span-6
(com/field {:label "Street 2"}
(com/text-input {:name (path->name [:vendor/address :address/street2])
:value (-> vendor :vendor/address :address/street2)
:placeholder "Suite 200"}))]
[:div.col-span-3
(com/field {:label "City"}
(com/text-input {:name (path->name [:vendor/address :address/city])
:value (-> vendor :vendor/address :address/city)
:placeholder "Cupertino"}))]
[:div.col-span-1
(com/field {:label "State"}
(com/text-input {:name (path->name [:vendor/address :address/state])
:value (-> vendor :vendor/address :address/state)
:placeholder "CA"}))]
[:div.col-span-2
(com/field {:label "Zip"}
(com/text-input {:name (path->name [:vendor/address :address/zip])
:value (-> vendor :vendor/address :address/zip)
:placeholder "98102"}))]
[:h4.text-xl.border-b.col-span-6 "Legal Entity"]
[:div.col-span-6
(com/field {:label "Legal Entity Name"}
(com/text-input {:name (path->name [:vendor/legal-entity-name])
:value (-> vendor :vendor/legal-entity-name)
:placeholder "Good Restaurant LLC"}))]
[:div.col-span-6.text-center " - OR -"]
[:div.col-span-2
(com/field {:label "First Name"}
(com/text-input {:name (path->name [:vendor/legal-entity-first-name])
:value (-> vendor :vendor/legal-entity-first-name)
:placeholder "John"}))]
[:div.col-span-2
(com/field {:label "Middle Name"}
(com/text-input {:name (path->name [:vendor/legal-entity-middle-name])
:value (-> vendor :vendor/legal-entity-middle-name)
:placeholder "C."}))]
[:div.col-span-2
(com/field {:label "Last Name"}
(com/text-input {:name (path->name [:vendor/legal-entity-last-name])
:value (-> vendor :vendor/legal-entity-last-name)
:placeholder "Riley"}))]
[:div.col-span-2
(com/field {:label "TIN"}
(com/text-input {:name (path->name [:vendor/legal-entity-tin])
:value (-> vendor :vendor/legal-entity-tin)
:placeholder "John"}))]
[:div.col-span-2
(com/field {:label "TIN Type"}
(com/select {:name (path->name [:vendor/legal-entity-tin-type])
:allow-blank? true
:value (some-> vendor :vendor/legal-entity-tin-type :db/ident name)
:options [["ein" "EIN"]
["ssn" "SSN"]]}))]
[:div.col-span-2
(com/field {:label "1099 Type"}
(com/select {:name (path->name [:vendor/legal-entity-1099-type])
:allow-blank? true
:value (some-> vendor :vendor/legal-entity-1099-type :db/ident name)
:options [["none" "None"]
["misc" "Misc"]
["landlord" "Landlord"]]}))]
[:div.col-span-6
(com/button {:color :primary}
"Save")]]]
[:div])]]))))
(com/modal
{}
[:form {:hx-post (str (bidi/path-for ssr-routes/only-routes
:company-1099-vendor-save
:request-method :post
:vendor-id (Long/parseLong (:vendor-id (:params request)))))
:hx-target "#vendor-table"
:hx-swap "outerHTML swap:300ms"}
[:fieldset {:class "hx-disable"}
(com/modal-card
{}
[:div.flex [:div.p-2 "Vendor 1099 Info"] [:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600 (:vendor/name vendor)]]
[:div.space-y-6
[:div.grid.grid-cols-6.gap-4
[:h4.text-xl.border-b.col-span-6 "Address"]
[:div.col-span-6
(com/field {:label "Street 1"}
(com/text-input {:name (path->name [:vendor/address :address/street1])
:value (-> vendor :vendor/address :address/street1)
:placeholder "1700 Pennsylvania Ave"
:autofocus true}))]
[:div.col-span-6
(com/field {:label "Street 2"}
(com/text-input {:name (path->name [:vendor/address :address/street2])
:value (-> vendor :vendor/address :address/street2)
:placeholder "Suite 200"}))]
[:div.col-span-3
(com/field {:label "City"}
(com/text-input {:name (path->name [:vendor/address :address/city])
:value (-> vendor :vendor/address :address/city)
:placeholder "Cupertino"}))]
[:div.col-span-1
(com/field {:label "State"}
(com/text-input {:name (path->name [:vendor/address :address/state])
:value (-> vendor :vendor/address :address/state)
:placeholder "CA"}))]
[:div.col-span-2
(com/field {:label "Zip"}
(com/text-input {:name (path->name [:vendor/address :address/zip])
:value (-> vendor :vendor/address :address/zip)
:placeholder "98102"}))]
[:h4.text-xl.border-b.col-span-6 "Legal Entity"]
[:div.col-span-6
(com/field {:label "Legal Entity Name"}
(com/text-input {:name (path->name [:vendor/legal-entity-name])
:value (-> vendor :vendor/legal-entity-name)
:placeholder "Good Restaurant LLC"}))]
[:div.col-span-6.text-center " - OR -"]
[:div.col-span-2
(com/field {:label "First Name"}
(com/text-input {:name (path->name [:vendor/legal-entity-first-name])
:value (-> vendor :vendor/legal-entity-first-name)
:placeholder "John"}))]
[:div.col-span-2
(com/field {:label "Middle Name"}
(com/text-input {:name (path->name [:vendor/legal-entity-middle-name])
:value (-> vendor :vendor/legal-entity-middle-name)
:placeholder "C."}))]
[:div.col-span-2
(com/field {:label "Last Name"}
(com/text-input {:name (path->name [:vendor/legal-entity-last-name])
:value (-> vendor :vendor/legal-entity-last-name)
:placeholder "Riley"}))]
[:div.col-span-2
(com/field {:label "TIN"}
(com/text-input {:name (path->name [:vendor/legal-entity-tin])
:value (-> vendor :vendor/legal-entity-tin)
:placeholder "John"}))]
[:div.col-span-2
(com/field {:label "TIN Type"}
(com/select {:name (path->name [:vendor/legal-entity-tin-type])
:allow-blank? true
:value (some-> vendor :vendor/legal-entity-tin-type :db/ident name)
:options [["ein" "EIN"]
["ssn" "SSN"]]}))]
[:div.col-span-2
(com/field {:label "1099 Type"}
(com/select {:name (path->name [:vendor/legal-entity-1099-type])
:allow-blank? true
:value (some-> vendor :vendor/legal-entity-1099-type :db/ident name)
:options [["none" "None"]
["misc" "Misc"]
["landlord" "Landlord"]]}))]
[:div.col-span-6
(com/button {:color :primary}
"Save")]]]
[:div])]]))))
(defn vendor-table [request]
(html-response (table* request)
@@ -323,11 +325,13 @@
(defn page [{:keys [identity matched-route] :as request}]
(base-page
request
(com/page {:nav (com/company-aside-nav)
(com/page {:nav (com/company-aside-nav)
:active-client (:client (:session request))
:identity (:identity request)}
:identity (:identity request)}
(com/breadcrumbs {}
[:a {:href "#"} "My Company"]
[:a {:href "#"} "1099 Vendor Info"])
[:a {:href (bidi/path-for ssr-routes/only-routes
:company)} "My Company"]
[:a {:href (bidi/path-for ssr-routes/only-routes
:company-1099)} "1099 Vendor Info"])
(table* request))
nil))

View File

@@ -110,8 +110,10 @@
:active-client (:client (:session request))
:identity (:identity request)}
(com/breadcrumbs {}
[:a {:href "#"} "My Company"]
[:a {:href "#"} "Reports"])
[:a {:href (bidi/path-for ssr-routes/only-routes
:company)} "My Company"]
[:a {:href {:href (bidi/path-for ssr-routes/only-routes
:company-reports)}} "Reports"])
(table* {:client (:client (:session request))
:start (some-> (or (get query-params "start") (get hx-query-params "start")) not-empty (Long/parseLong ))
:per-page (some-> (or (get query-params "per-page") (get hx-query-params "per-page")) not-empty (Long/parseLong ))

View File

@@ -0,0 +1,168 @@
(ns auto-ap.ssr.company.yodlee
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.datomic.yodlee2 :as yodlee2]
[auto-ap.graphql.utils :refer [is-admin?]]
[auto-ap.ssr-routes :as ssr-routes]
[auto-ap.ssr.components :as com]
[auto-ap.ssr.svg :as svg]
[auto-ap.ssr.ui :refer [base-page]]
[auto-ap.ssr.utils :refer [html-response]]
[auto-ap.time :as atime]
[auto-ap.yodlee.core2 :as yodlee]
[bidi.bidi :as bidi]
[config.core :refer [env]]
[datomic.api :as dc]
[hiccup2.core :as hiccup]))
(defn row* [{:keys [flash? yodlee-provider-account identity delete-after-settle?]}]
(com/data-grid-row
{:class (when flash?
"live-added")
"_" (hiccup/raw (when delete-after-settle?" on htmx:afterSettle wait 400ms then remove me"))}
(com/data-grid-cell
{}
(:yodlee-provider-account/id yodlee-provider-account))
(com/data-grid-cell
{}
(when-let [status (:yodlee-provider-account/status yodlee-provider-account)]
(com/pill {:color (if (not= status "SUCCESS")
:yellow
:primary) }
status)))
(com/data-grid-cell
{}
(when-let [status (:yodlee-provider-account/detailed-status yodlee-provider-account)]
status)
)
(com/data-grid-cell
{}
(atime/unparse-local (:yodlee-provider-account/last-updated yodlee-provider-account)
atime/normal-date))
(com/data-grid-cell
{}
[:ul
(for [a (:yodlee-provider-account/accounts yodlee-provider-account)]
[:li (:yodlee-account/name a) " - " (:yodlee-account/number a) #_[:div.tag (->$ (:available-balance a))]])])
(com/data-grid-right-stack-cell
{}
(when (is-admin? identity)
[:form
[:input {:type :hidden :name "id" :value (:db/id yodlee-provider-account)}]
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
:company-yodlee-provider-account-refresh)
:hx-target "closest tr"}
svg/refresh)])
#_(when (is-admin? identity)
[:form
[:input {:type :hidden :name "id" :value (:db/id report)}]
(com/icon-button {:hx-delete (str (bidi/path-for ssr-routes/only-routes
:company-reports-delete
:request-method :delete))
:hx-target "closest tr"}
svg/trash)]))))
(defn table* [{:keys [identity start per-page client flash-id]}]
(let [start (or start 0)
per-page (or per-page 30)
[yodlee-provider-accounts total] (yodlee2/get-graphql {:id identity
:start start
:per-page per-page
:client-id (:db/id client)
:sort nil})]
[:div
(com/data-grid-card {:id "yodlee-table"
:title "Yodlee Accounts"
:entity-name "Yodlee accounts"
:route :company-yodlee-table
:start start
:per-page per-page
:total total
:action-buttons [(com/button {:color :primary
:on-click "openFastlink()"
:hx-get (bidi/path-for ssr-routes/only-routes
:company-yodlee-fastlink-dialog)
:hx-target "#modal-holder"}
(com/button-icon {} svg/refresh)
"Link new account")]
:rows (for [yodlee-provider-account yodlee-provider-accounts]
(row* {:yodlee-provider-account yodlee-provider-account
:flash? (= flash-id
(:db/id yodlee-provider-account))
:identity identity}))
:headers [(com/data-grid-header {} "Provider Account")
(com/data-grid-header {} "Status")
(com/data-grid-header {} "Detailed Status")
(com/data-grid-header {} "Last Updated")
(com/data-grid-header {:class "hidden md:table-cell"} "Accounts")
(com/data-grid-header {})]})]))
(def default-read '[:db/id
:yodlee-provider-account/last-updated
:yodlee-provider-account/status
:yodlee-provider-account/id
:yodlee-provider-account/detailed-status
{:yodlee-provider-account/accounts [:yodlee-account/name :yodlee-account/number]
:yodlee-provider-account/client [:client/code]}])
(defn refresh-provider-account [{:keys [form-params identity]}]
(let [provider-account (dc/pull (dc/db conn) default-read (some-> (get form-params "id") not-empty Long/parseLong))]
(yodlee/refresh-provider-account (:client/code (:yodlee-provider-account/client provider-account))
(:yodlee-provider-account/id provider-account))
(html-response
(row* {:yodlee-provider-account provider-account
:flash? true
:identity identity}))))
(defn fastlink-dialog [{:keys [session]}]
(html-response
(com/modal
{}
(com/modal-card
{}
[:div.flex [:div.p-2 "Yodlee Fastlink"] ]
[:div
[:div#fa-spot]
[:script {:lang "text/javascript"}
(hiccup/raw
(format "
fastlink.open({fastLinkURL: '%s',
accessToken: '%s',
params: {'configName': 'Aggregation'}},
'fa-spot');
" (:yodlee2-fastlink env) (yodlee/get-access-token (:client/code (:client session)))))]
]
[:div]))))
(defn table [{:keys [query-params hx-query-params identity session] :as request}]
(html-response (table* {:client (:client (:session request))
:start (some-> (or (get query-params "start") (get hx-query-params "start")) not-empty (Long/parseLong ))
:per-page (some-> (or (get query-params "per-page") (get hx-query-params "per-page")) not-empty (Long/parseLong ))
:identity identity
:session session})
:headers {"hx-push-url" (str "?start=" (get (:query-params request) "start"))}))
(defn page [{:keys [identity matched-route query-params :hx-query-params session] :as request}]
(base-page
request
(com/page {:nav (com/company-aside-nav)
:active-client (:client (:session request))
:identity (:identity request)}
(com/breadcrumbs {}
[:a {:href (bidi/path-for ssr-routes/only-routes
:company)}
"My Company"]
[:a {:href (bidi/path-for ssr-routes/only-routes
:company-yodlee)}
"Yodlee"]
)
(table* {:client (:client session)
:start (some-> (or (get query-params "start") (get hx-query-params "start")) not-empty (Long/parseLong ))
:per-page (some-> (or (get query-params "per-page") (get hx-query-params "per-page")) not-empty (Long/parseLong ))
:identity identity
:session session}))
nil))